git add -A 没有在目录中添加所有修改过的文件

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7726131/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 12:02:24  来源:igfitidea点击:

git add -A is not adding all modified files in directories

gitrecursion

提问by Rakib

I want to add all files no matter what: whether it is deleted, created, modified, untracked, etc? I just don't want to git add ALLmy files EVERY TIME. I tried git add -Abut it is NOTadding modified files inside folders.

无论如何我都想添加所有文件:是否已删除、创建、修改、未跟踪等?我只是不想git的添加所有我的文件EVERY TIME。我试过了,git add -A但它没有在文件夹中添加修改过的文件。

Here is my initial git statusin my project:

这是我git status在我的项目中的首字母:

Rakib-MacBook-Pro:my-xcode-practice rakib$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   BankAccount (modified content, untracked content)
#   modified:   BuckysButtons (modified content, untracked content)
#   modified:   multiview (modified content, untracked content)
#   modified:   rotator (modified content, untracked content)
#   modified:   segmentedControls (modified content, untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

Then I put git add -A:

然后我把git add -A

Rakib-MacBook-Pro:my-xcode-practice rakib$ git add -A

and then here is the new status AFTERdoing git add -A:

然后这里是新的状态git add -A

Rakib-MacBook-Pro:my-xcode-practice rakib$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#   (commit or discard the untracked or modified content in submodules)
#
#   modified:   BankAccount (modified content, untracked content)
#   modified:   BuckysButtons (modified content, untracked content)
#   modified:   multiview (modified content, untracked content)
#   modified:   rotator (modified content, untracked content)
#   modified:   segmentedControls (modified content, untracked content)
#
no changes added to commit (use "git add" and/or "git commit -a")

You can see that there has been no change in the git status. How do I solve this?

可以看到没有任何变化git status。我该如何解决这个问题?

I also tried git add .- it did not help

我也试过git add .- 它没有帮助

I also tried git add *- it did not help

我也试过git add *- 它没有帮助

采纳答案by Mark Longair

The problem here is that BankAccount, BuckysButtons, multiview, rotatorand segmentedControlsare all git submodules, which act like independent repositories in many ways.

这里的问题是BankAccount, BuckysButtons, multiview,rotatorsegmentedControls都是 git 子模块,它们在很多方面都像独立的存储库。

If what you want to do is to run git add -A .in each submodule, you could do:

如果你想做的是git add -A .在每个子模块中运行,你可以这样做:

git submodule foreach --recursive git add -A .

And then you could create a commit in every submodule with:

然后你可以在每个子模块中创建一个提交:

git submodule foreach --recursive "git commit -m 'Committing in a submodule'"

(If you don't have other submodules nested inside those submodules, the --recursiveoption is unnecessary.)

(如果这些子模块中没有嵌套其他子模块,--recursive则不需要该选项。)

However, I don't recommend doing this. You should carefully change into each submodule in turn, and consider how you want to update them, treating each as a standalone repository. Then only commit these new submodule versions in the main project when you have tested that the project as a whole works with those new versions of each submodule.

但是,我不建议这样做。您应该仔细地依次更改每个子模块,并考虑如何更新它们,将每个子模块视为一个独立的存储库。然后,当您测试整个项目与每个子模块的这些新版本一起工作时,仅在主项目中提交这些新的子模块版本。



Update:It seems from the error message that you've quoted in the comments below that you have added these other git repositories directly rather than as submodules. This can happen if you copy another git repository into your repository and then just use git addto stage it, rather than adding it with git submodule add <REPOSITORY-URL>. If you really intend these to be stored as submodules, I would suggest moving them out of your repository, committing their deletion, and then add them properly as submodules with git submodule add

更新:从您在下面的评论中引用的错误消息看来,您已经直接添加了这些其他 git 存储库,而不是作为子模块添加。如果您将另一个 git 存储库复制到您的存储库中,然后仅用于暂存git add它,而不是使用 .git 将其添加,则会发生这种情况git submodule add <REPOSITORY-URL>。如果您真的打算将它们存储为子模块,我建议将它们从存储库中移出,提交删除,然后将它们正确添加为子模块git submodule add

回答by Patrick Lee Scott

I just recreated this by accident.

我只是偶然地重新创建了这个。

I copied a project I had in another folder into my new git repo. I didn't intend to use it as a submodule, I intended to use it as a starting point for a new project. The project I copied which was now a subfolder of my main git repo had .git/in it. Delete subfolder/.git/.

我将另一个文件夹中的项目复制到我的新 git 存储库中。我不打算将它用作子模块,我打算将它用作新项目的起点。我复制的项目现在是我的主 git 存储库的子文件夹.git/。删除subfolder/.git/

rm -rf subfolder/.git


Then things were still weird...

然后事情还是很奇怪......

git status

Nothing to commit. Hmm... What about all of these files?

没什么可承诺的。嗯...所有这些文件呢?

I didn't really know how to fix this properly with git, so I duplicated the directory, and deleted the original.

我真的不知道如何用 git 正确解决这个问题,所以我复制了目录,并删除了原来的。

cp subfolder newsubfolder    
rm -rf subfolder

Then I added all changed files, committed, and pushed.

然后我添加了所有更改的文件,提交并推送。

git add -A
git commit -am 'i did something and there are now files'
git push origin <branchName>

回答by Ben

A pretty simple fix for me - I had opened the Git Bash in a subdirectory of the project.

对我来说一个非常简单的修复 - 我在项目的子目录中打开了 Git Bash。

Open the Bash and doing the commands in the root directory fixed this problem; git add -A .worked as expected.

打开Bash,在根目录下执行命令修复了这个问题;git add -A .按预期工作。

回答by theBushman

I solved this by deleting the .git folders inside the supposed submodules and inside the project root, and then doing a new 'git init'

我通过删除假定的子模块和项目根目录中的 .git 文件夹来解决这个问题,然后执行一个新的 'git init'

回答by nilansh bansal

This error occurs because you have added a folder which is already linked with some another github repository .

发生此错误是因为您添加了一个已与另一个 github 存储库链接的文件夹。

To solve this issue first copy the files you want to upload to github from the BankAccount folder and then delete the BankAccount folder.

要解决这个问题,首先将要上传的文件从BankAccount文件夹复制到github,然后删除BankAccount文件夹。

Now make a new folder and then paste the files in it.

现在创建一个新文件夹,然后将文件粘贴到其中。

It is due to the git submodules that is automatically taken by git present in the earlier folder.

这是由于存在于较早文件夹中的 git 自动采用了 git 子模块。

Now you can do

现在你可以做

git add . 
git status

回答by bmargulies

Let's quote the documentation for -A:

让我们引用 -A 的文档:

       -A, --all
       Like -u, but match <filepattern> against files in the working tree in addition to the
       index. That means that it will find new files as well as staging modified content and
       removing files that are no longer in the working tree.

Note the critical word: <filepattern>. You need to give it a pattern that matches, recursively, all the way down your tree.

注意关键词:<filepattern>。你需要给它一个匹配的模式,递归地,一直到你的树。

回答by insanebits

I had a similar problem on Windows where I git add --allleft some files untracked, problem was that there were several files with different casing 'test.php' and 'Test.php' so git tracked Test.php and not lowercase version of it.

我在 Windows 上遇到了类似的问题,我git add --all没有跟踪一些文件,问题是有几个文件具有不同的大小写 'test.php' 和 'Test.php' 所以 git 跟踪 Test.php 而不是它的小写版本。

This may help someone in future and save some head scratching.

这可能会在将来对某人有所帮助并避免一些头疼。

回答by Tahir Khalid

I had this very issue the past couple of days with BitBucket. I am working on a project that is being tracked in its repository by Visual Studio 2013 Community Edition.

过去几天我在使用 BitBucket 时遇到了这个问题。我正在处理一个由 Visual Studio 2013 社区版在其存储库中跟踪的项目。

However I had used Git Bash on occasion to manually do commits and that's when things started to go wrong and files were simply being ignored. Tried to reclone the repo but this didn't help.

然而,我偶尔会使用 Git Bash 来手动提交,那是当事情开始出错并且文件被简单地忽略的时候。试图重新克隆回购,但这没有帮助。

Finally I found that if you go into Visual Studio > Team Explorer > click on Sync, Visual Studio will do a pull and then commit and push any untracked files.

最后我发现,如果您进入 Visual Studio > Team Explorer > 单击 Sync,Visual Studio 将执行拉取操作,然后提交并推送任何未跟踪的文件。

You could do the same manually through Git Bash if you like the console like I do.

如果你像我一样喜欢控制台,你可以通过 Git Bash 手动执行相同的操作。

Hope this helps someone.

希望这可以帮助某人。

回答by AndyZe

I had this issue because I cloned somebody else's repository into my project. When I cloned it, there were already .git and .gitignore folders/files from their project. After deleting those pre-existing git files and starting over with git again, it works fine.

我遇到这个问题是因为我将别人的存储库克隆到我的项目中。当我克隆它时,他们的项目中已经有 .git 和 .gitignore 文件夹/文件。删除那些预先存在的 git 文件并再次使用 git 重新开始后,它工作正常。