简体   繁体   English

我想以某种方式推送我所有的文件,然后我可以在存储库中打开它们

[英]I want to push all my files in a way that I can open them all on repository afterwards

I have no idea what happened that Git started telling me that I added another git repository inside my current repository.我不知道 Git 开始告诉我我在当前存储库中添加了另一个 git 存储库发生了什么。 I don't remember doing that, I have been working on writing code and configuration files all day.我不记得这样做了,我整天都在写代码和配置文件。

So it gave me this warning: adding embedded git repository: client所以它给了我这个warning: adding embedded git repository: client

I tried doing git rm --cached client -f , Git didn't care, warning still there.我试着做git rm --cached client -f ,Git 不在乎,警告仍然存在。

so I did a git add .所以我做了一个git add .

When I pushed the project, I could not open up the client/ folder as a link on the Github repository.当我推送项目时,我无法打开client/文件夹作为 Github 存储库上的链接。

I deleted the Github repository.我删除了 Github 存储库。

I am back to changes not staged for commit: modified: client (modified content, untracked content) , it does not let me do git checkout -- client/ either.我回到了未为提交暂存的更改:已modified: client (modified content, untracked content) ,它也不让我执行git checkout -- client/

I essentially want to ensure that when I create a repo for this project and push all these folder that I am able to click on the folders and view the files inside of them.我基本上想确保当我为这个项目创建一个 repo 并推送所有这些文件夹时,我能够点击文件夹并查看其中的文件。

This is my Dockerfile.dev inside of client/ :这是我在client/ Dockerfile.dev

FROM node:alpine
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
CMD ["npm", "run", "start"]

This is my Dockerfile for production purposes inside of client/ :这是我在client/用于生产目的的Dockerfile

FROM node:alpine
WORKDIR '/app'
COPY ./package.json ./
RUN npm install
COPY . .
RUN npm run build

FROM nginx
EXPOSE 3000
COPY ./nginx/default.conf /etc/nginx/conf.d/default.conf
COPY --from=builder /app/build /usr/share/nginx/html

I don't believe any of the configuration above could have create a .git folder inside of client/ .我不相信上面的任何配置都可以在client/内创建一个.git文件夹。

I looked through my command line history and I do not see where I ran a git init on the client/ directory.我查看了命令行历史记录,但没有看到在client/目录上运行git init的位置。

At this point how do I clean this up?在这一点上我如何清理它? git rm --cached client did not seem to work and neither did git clean -f -d . git rm --cached client似乎没有工作, git clean -f -d也没有。

I am back to我回来了

changes not staged for commit: modified: client (modified content, untracked content)

This indicates that your existing Git repository is treating the path-name client as a submodule .这表明您现有的 Git 存储库将路径名client视为子模块 A submodule is nothing more or less than a particular form of reference to some other Git repository.子模块只不过是对其他Git 存储库的特定引用形式。

This whole picture can get confusing very quickly, since every local (eg, on-your-laptop) Git repository usually contains a reference to another Git repository already: the one that's on your hosting provider, such as GitHub.整个画面很快就会变得混乱,因为每个本地(例如,在您的笔记本电脑上)Git 存储库通常已经包含对另一个 Git 存储库的引用:位于您的托管服务提供商(例如 GitHub)上的那个。 That is, if we draw a relationship, we get something like this:也就是说,如果我们绘制一个关系,我们会得到这样的结果:

+-----------------+                +-----------------+
|  your Git repo  |   --origin->   |   GitHub repo   |
|=================|                |=================|
|    commits      |                |     commits     |
|  (shared w/     |   <=========>  |                 |
|   origin)       |                |                 |
|-----------------|                |                 |
|   branch names  | (private)      |                 |
|-----------------|                |-----------------|
| remote-tracking |                |  branch names   |
| names: origin/* | <------------- |                 |
+-----------------+                +-----------------+

There are two repositories, one on your laptop (your Git repo) and one on GitHub or Bitbucket or GitLab or whatever.有两个存储库,一个在您的笔记本电脑(您的 Git 存储库)上,另一个在 GitHub、Bitbucket 或 GitLab 或其他任何地方。 Yours calls theirs origin .你的称为他们的origin You and they share commits by copying back and forth: you run git fetch to get new commits from them, and you run git push to send new commits to them.你和他们通过来回复制来共享提交:你运行git fetch从他们那里获取新的提交,你运行git push他们发送新的提交。 They have branch names like master and develop and so on, and you have branch names, but you also have remote-tracking names like origin/master .它们有像masterdevelop等分支名称,你有分支名称,但你也有像origin/master这样的远程跟踪名称 Your Git simply copies their branch names to your repo, while adding origin/ —the name you are using to hold the URL for the GitHub repo—in front.您的 Git 只需将它们的分支名称复制到您的存储库,同时在前面添加origin/您用来保存 GitHub 存储库 URL 的名称)。

Each of the commits in these two repositories, like any commit, has a unique hash ID.这两个存储库中的每个提交,就像任何提交一样,都有一个唯一的哈希 ID。 If you and they have the same hash ID for some commit, you have the same commit .如果您和他们对某些提交具有相同的哈希 ID,则您具有相同的 commit So when your Git talks with their Git, it can just ask: do you have hash ID a123456... ?所以当你的 Git 与他们的 Git 交谈时,它只会问:你有哈希 ID a123456...吗? or tell it: here's commit a123456... and provide the full contents of that commit.或者告诉它:这是提交a123456...并提供该提交的完整内容。

Submodules子模块

So far so good, but now you've thrown a submodule into the mix.到目前为止一切顺利,但现在您已经将一个子模块加入其中。

In a submodule, each of your commits holds the raw hash ID of a commit in some other Git repository.在子模块中,您的每个提交都包含某个其他 Git 存储库中提交的原始哈希 ID。 This "other Git repository" is a third Git repo:这个“其他 Git 存储库”是第三个Git 存储库:

          +-----------------+
          |  your Git repo  |
          |=================|
a123456 > |    commits      |
   |      |-----------------|
   |      |   branch names  |
   |      |-----------------|
   |      | remote-tracking |
   |      | names: origin/* |
   |      +-----------------+
   |
   |          +--------------+              +--------------+
   +--------> | README.md    |              | README.md    |
              | file1        |              | file3        |
              | dir1/file2   |              | file4        |
              | client ------|---> b789abc: | ...          |
              +--------------+              +--------------+

where b789abc... is actually a commit in this third repo.其中b789abc...实际上是第三个repo 中的提交。 This third repo of course can also have its own origin , which would be a fourth repository in the picture.这第三个 repo 当然也可以有自己的origin ,这将是图中的第四个存储库。 That fourth repository is also presumably on GitHub or Bitbucket or GitLab or whatever.第四个存储库大概也在 GitHub 或 Bitbucket 或 GitLab 或其他任何地方。

To work with a submodule properly, your own repository—the one Git calls a superproject , which is the one on the left in this second diagram—must contain a file named .gitmodules .要正确使用子模块,您自己的存储库(Git 称为superproject的存储库,即第二个图中左侧的存储库)必须包含一个名为.gitmodules的文件。 This file lists the URL of the fourth Git repository , ie, the one we didn't draw here.该文件列出了第四个 Git 存储库URL ,即我们这里没有绘制的那个。

In this case, we've shown a commit in your repository that contains snapshots of files, plus a gitlink .在这种情况下,我们在您的存储库中显示了一个包含文件快照的提交,以及一个gitlink This gitlink says that for the name client , whoever is working with this repository should clone the submodule repository and tell that Git to git checkout b789abc... (by its unique hash ID).这gitlink说,对于名client ,谁与此库的工作应该克隆子模块库,并告诉Git用git checkout b789abc... (通过其独特的哈希ID)。

The URL you are to store in .gitmodules enables anyone who clones your GitHub repository to also clone this fourth repository.您要存储在.gitmodules的 URL 使克隆您的 GitHub 存储库的任何人也可以克隆第四个存储库。 After that, their local (laptop) clone can use the hash ID—in this case b789abc... —stored in the gitlink entries of the commits that are shared in your laptop and GitHub superproject repositories, to git checkout the right hash ID in their local Git repository that they make by cloning this fourth Git repository.之后,他们的本地(笔记本电脑)克隆可以使用哈希b789abc...在本例中为 b789abc...——存储在你的笔记本电脑和 GitHub 超级项目存储库中共享的提交的 gitlink 条目中,以git checkout的正确哈希 ID他们通过克隆第四个 Git 存储库创建的本地 Git 存储库。

(You might need to read over this section many times. It's complicated!) (您可能需要多次阅读此部分。这很复杂!)

What if you don't want a submodule?如果您不想要子模块怎么办?

If you don't want a submodule at all:如果您根本不需要子模块:

  1. Move the other Git repository completely out of the way:将另一个 Git 存储库完全移开:

     mv client /some/other/path

    (or whatever you use to move everything, including the .git folder). (或者你用来移动所有东西的任何东西,包括.git文件夹)。

  2. Copy all the files , but not the .git directory/folder, from the place you moved all this stuff to.复制所有文件,但不复制.git目录/文件夹,从您将所有这些内容移动到的位置。

(Another way to do this that might be easier: move the .git directory out of the client/ subdirectory, or remove it entirely.) (另一种可能更简单的方法是:将.git目录移出client/子目录,或将其完全删除。)

Now you have ordinary files—which you did before—but ordinary files that you can git add in the ordinary way because there's no .git folder in the client/ folder standing in the way.现在你有普通文件——你以前做过——但是普通文件你可以用普通的方式git add因为client/文件夹中没有.git文件夹阻碍。 Your Git repository won't try to control some other Git repository via all this submodule stuff.您的 Git 存储库不会尝试通过所有这些子模块内容来控制其他一些 Git 存储库。

Unfortunately, you must do this after getting rid of any submodule that you already created.不幸的是,您必须删除您已经创建的任何子模块执行此操作。 This is painful.这很痛苦。 Be very sure you want to do this.非常确定你想这样做。 If you have existing commits that list client as a submodule, you'll have to either be very careful whenever you use those existing commits, or do a major history rewrite operation to replace all those commits with new-and-improved ones that don't use client as a submodule.如果您有将client列为子模块的现有提交,则无论何时使用这些现有提交都必须非常小心,或者执行主要的历史重写操作以将所有这些提交替换为新的和改进的提交,而不是“ t使用client作为子模块。

See the last section below if you haven't made any commits that refer to this submodule and don't have a .gitmodules file.如果您没有进行任何引用此子模块的提交并且没有.gitmodules文件,请参阅下面的最后一节。

What if you do want a submodule, but just want to update it?如果您确实想要一个子模块,但只想更新它怎么办?

This gets a little bit tricky, but it's really not that bad.这有点棘手,但实际上并没有那么糟糕。 Remember: the submodule is a Git repository.请记住:子模块一个 Git 存储库。 It should have a counterpart over on GitHub or whatever, which the submodule calls origin .它应该在 GitHub 或其他地方有一个对应物,子模块称之为origin The submodule itself has little or no idea that it's living underneath a superproject: it's just a regular old Git repository.子模块本身很少或根本不知道它存在于一个超级项目之下:它只是一个普通的旧 Git 存储库。 The only thing special is that the superproject tends to cd into the submodule Git and tell it to git checkout one commit by hash ID, putting it into detached HEAD mode.唯一特别的是超级项目倾向于cd进入子模块 Git 并告诉它通过哈希 ID git checkout一次提交,将其置于分离的 HEAD模式。

So: enter the submodule yourself, and take it out of "detached HEAD" mode, by either creating a new branch name for the current commit, or checking out some existing branch name.所以:自己进入子模块,通过为当前提交创建一个新的分支名称,或者检查一些现有的分支名称,将它从“分离的 HEAD”模式中取出。 If you have changes that you need to save, you can git stash them or make a commit here first, then return to this commit later.如果您有需要保存的更改,您可以git stash它们git stash或先在此处提交,然后再返回到此提交。 If your changes are really simple—say, updating the README file slightly—you can just re-create them.如果您的更改非常简单——例如,稍微更新README文件——您可以重新创建它们。

Now, re-create your changes on this branch, or commit them on this branch whose name you just invented, or whatever it takes to commit them on some branch:现在,在这个分支上重新创建你的更改,或者在你刚刚命名的这个分支上提交它们,或者在某个分支上提交它们需要什么:

... do work ...
git add <files>
git commit

(and supply commit message, etc). (并提供提交信息等)。 You'll see that this makes a new commit, which gets its own new unique big ugly hash ID.你会看到这会产生一个新的提交,它获得了自己新的唯一的、丑陋的大哈希 ID。 You can now git push or use a pull request to send this new commit, under its new or existing branch name, to the fourth Git repository, the one this submodule Git calls origin .您现在可以git push或使用拉取请求将这个新提交以新的或现有的分支名称发送到第四个Git 存储库,这个子模块 Git 调用origin

(If you have to go through a pull request, this can take a long time, obviously. If you like to live dangerously, you can go ahead and use the new hash ID on the assumption that whoever controls the pull requests will take your commit as is. If not, wait until they take it, or notify users that they might not be able to use the superproject update you're about to make. Remember, your superproject records raw hash IDs . If the people controlling the PRs take your changes slightly differently, the commit they put into the upstream repo will have a different hash ID, and you'll have to update your submodule again.) (如果你必须通过拉取请求,这可能需要很长时间,显然。如果你喜欢危险的生活,你可以继续使用新的哈希 ID,假设控制拉取请求的人会接受你的提交按原样。如果没有,请等到他们接受,或者通知用户他们可能无法使用您即将进行的超级项目更新。请记住,您的超级项目记录原始哈希 ID 。如果控制 PR 的人接受了您的稍有不同,他们放入上游存储库的提交将具有不同的哈希 ID,您将不得不再次更新您的子模块。)

Now your new commit in the submodule is available to everyone else too.现在,您在子模块中的新提交也可供其他所有人使用。 You're now done updating the submodule, and can go back to the superproject:你现在已经完成了子模块的更新,可以回到超级项目:

cd ..     # or whatever to get to the superproject

Running git status in the superproject will now show that the submodule has a new commit in it.在超级项目中运行git status现在将显示子模块中有一个新的提交 (Running git diff or git submodule status will show similar things, although you can configure git diff to show actual diffs instead of just a raw hash ID. You can configure git status in complicated ways here too, but the default is to just say (new commits) .) (运行git diffgit submodule status会显示类似的东西,虽然你可以配置git diff来显示实际的差异,而不仅仅是原始哈希 ID。你也可以在这里以复杂的方式配置git status ,但默认情况下只是说(new commits) 。)

Your job is now to record the new hash ID in the gitlink that will be committed in your next commit:您现在的工作是在下次提交时提交的 gitlink 中记录新的哈希 ID

git add client

Now the changes are staged— git status will show them under changes staged for commit this time.现在更改已暂存 - git status将在这次changes staged for commit下显示它们。 Now you can git commit the result as an updated gitlink, along with everything else that goes into each new commit you make.现在,您可以将结果作为更新的 gitlink 以及进入您所做的每个新提交的所有其他内容进行git commit You now have an ordinary commit—just, one that uses a gitlink to refer to a commit in a third Git repo that refers to a fourth Git repo, that your superproject calls a submodule.你现在有一个普通的提交——只是,一个使用 gitlink 来引用第三个 Git 存储库中的提交,该提交引用第四个 Git 存储库,你的超级项目称之为子模块。

What if you don't want a submodule, don't have a .gitmodules , etc, and have not made any commits with this weird submodule stuff yet?如果你想要一个子模块,没有.gitmodules等,并且还没有对这个奇怪的子模块内容进行任何提交怎么办?

(Note: It sounds like you have already made some commits, because you talked about looking at the commits via the GitHub web browser. So this may not apply at all.) (注:这听起来像你已经取得了一定的提交,因为你谈到望着通过GitHub的Web浏览器提交所以这可能根本不适用。)

If you have run:如果你已经运行:

git add client

and client has its own .git , a modern Git will notice and create the first part—but only the first part—of a submodule: a sort of half-baked one.并且client有自己的.git ,现代 Git 会注意到并创建子模块的第一部分——但只是第一部分:一种半生不熟的。 This one is missing the .gitmodules file that tells future git clone operations where the fourth Git repository is, so that those folks' Gits can make their own third repositories.这个缺少.gitmodules文件,该文件告诉未来的git clone操作第四个 Git 存储库在哪里,以便那些人的 Git 可以创建他们自己的第三个存储库。

If you haven't committed this yet, though, this gitlink isn't in any commits.如果你还没有提交这个,这个 gitlink 不在任何提交中。 That makes cleaning it up easy.这使得清理它变得容易。 Just run:赶紧跑:

git rm --cached client

to remove the gitlink entry from your index/staging-area.从您的索引/暂存区域中删除 gitlink 条目。 Then, once you have de- .git -ified the client directory (ie, now if you already did this, in a moment if you haven't yet), you can git add client and it will add the files in the client folder (and recursively, any files in any sub-folders) this time.然后,一旦你有去.git -ified的client目录(例如,现在如果你已经这样做,如果您还没有片刻),你可以git add client ,它会在添加文件client文件夹(并且递归地,任何子文件夹中的任何文件)这次。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我可以将git储存库中的所有文件“推送”到ftp服务器(实时生产)吗? - Can I 'push' all the files in my git repository to my ftp server (live production)? 如何让“git push production”推送存储库中的所有文件? - How can I make "git push production" push all files in repository? Github:我无法推​​送所有文件 - Github: I can't push ALL my files 我无法将我的所有文件推送到bitbucket - I can't push all my files to bitbucket 从GitHub删除所有本地文件并下载存储库后,我不能使用git push - After deleting all local files and downloaded repository from GitHub, I can't use git push 不小心删除了.gitignore中记录的所有文件,我希望它们退回 - accidentally removed all files noted in .gitignore and I want them back 如何将所有分支推送到新创建的存储库? - How can I push all branch to a newly created repository? Git:强行清除了我所有的提交-我可以把它们找回来吗? - Git: force push cleared all of my commits - can I get them back? 如何删除 git repo 中的所有文件并从本地 git repo 更新/推送? - How can I remove all files in my git repo and update/push from my local git repo? 如何将已建立的本地git存储库链接到新的远程存储库并将所有文件推送到远程? - How do I link an already established local git repository to a new remote repository and push all files to remote?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM