git Git未跟踪文件列表错误
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11525358/
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
Git untracked files list is wrong
提问by TimmyJ
Somehow, git got it in its head that I have an untracked file (A directory that has been in my repository for quite some time, ~17 months). At any rate, I can't seem to convince git that this is not an untracked file. Furthermore, I can't re-add the file(s) in question. Any idea how I can fix this?
不知何故,git 意识到我有一个未跟踪的文件(这个目录已经在我的存储库中存在了很长一段时间,大约 17 个月)。无论如何,我似乎无法说服 git 这不是一个未跟踪的文件。此外,我无法重新添加有问题的文件。知道我该如何解决这个问题吗?
Example:
例子:
? git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# rosetta_tests/profile/tests/docking/
nothing added to commit but untracked files present (use "git add" to track)
I try to add the directory and re-check the status.
我尝试添加目录并重新检查状态。
? git add rosetta_tests/profile/tests/docking/
? git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# rosetta_tests/profile/tests/docking/
nothing added to commit but untracked files present (use "git add" to track)
Just to be sure (from the root of my source tree)
可以肯定的是(从我的源代码树的根)
? git add .
? git status
# On branch master
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# rosetta_tests/profile/tests/docking/
nothing added to commit but untracked files present (use "git add" to track)
What is going on here? How can I convince git to fix itself?
这里发生了什么?我怎样才能说服 git 自我修复?
EDIT
编辑
A few more details:
更多细节:
-The files are not in the .gitignore
- 文件不在 .gitignore 中
-There are three tracked files in the folder in question, so it's not empty
- 有问题的文件夹中有三个被跟踪的文件,所以它不是空的
-After even more digging, it seems something like this could arise from changing the case of a tracked folder. This, unfortunately, is not the case (pun!). The folder name has never changed case.
- 经过更多的挖掘,似乎可以通过更改跟踪文件夹的大小写来出现这种情况。不幸的是,情况并非如此(双关语!)。文件夹名称从未改变大小写。
-Contents of the docking directory:
- 对接目录的内容:
? ls -lA rosetta_tests/profile/tests/docking/.
total 16
-rw-r--r-- 1 tim staff 2209 Jul 17 10:47 command
-rw-r--r-- 1 tim staff 260 Jul 17 10:47 flags
drwxr-xr-x 3 tim staff 102 Jul 17 10:47 input
回答by Th 00 m? s
The . in the git add .
command refers to the "current directory". So, running git add .
will add all the files in the current directory and its subdirectories. You should ensure that you are in the correct directory before running git add
.
这 。在git add .
命令中指的是“当前目录”。因此,运行git add .
将添加当前目录及其子目录中的所有文件。在运行之前,您应该确保您位于正确的目录中git add
。
git add -A
is what you want. It will add everything.
git add -A
是你想要的。它将添加所有内容。
回答by Alex
I solved this by running
我通过运行解决了这个问题
git clean -f
回答by Rolf Staflin
I had the same error: no case changes, no .ignore problems and the directory did contain files that I definitely wanted to keep. Adding the dir, committing, git add -A
and other remedies did not have any effect.
我遇到了同样的错误:没有大小写更改,没有 .ignore 问题,并且目录确实包含我肯定想要保留的文件。添加目录、提交git add -A
和其他补救措施没有任何效果。
I ended up deleting the directory with "git clean" and then checking out the files inside the dir again.
我最终用“git clean”删除了目录,然后再次检查目录中的文件。
Here is what I did:
这是我所做的:
rex@sidekick> git status
# On branch master
# Your branch is ahead of 'origin/master' by 10 commits.
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# app/models/xSpecific/
nothing added to commit but untracked files present (use "git add" to track)
At this point I made a backup copy of the "xSpecific" directory just in case. Then I made a dry run with ′git clean′ (the -n option means "dry run" and -d makes clean remove directories):
此时我制作了“xSpecific”目录的备份副本以防万一。然后我用 'git clean' 进行了一次试运行(-n 选项表示“试运行”,-d 使清理删除目录):
rex@sidekick> git clean -n -d
Would remove app/models/xSpecific/
After double and triple checking, I went ahead with the cleaning (the -f flag means "force" and is needed to persuade Git that you are serious. Very good design, if you ask me):
经过双重和三次检查后,我继续进行清理(-f 标志的意思是“强制”,需要说服 Git 你是认真的。非常好的设计,如果你问我的话):
rex@sidekick> git clean -d -f
Removing app/models/xSpecific/
rex@sidekick> git status
# On branch master
# Your branch is ahead of 'origin/master' by 10 commits.
#
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: app/models/xSpecific/GetAddressesLog.java
# deleted: app/models/xSpecific/GetProductLog.java
#
no changes added to commit (use "git add" and/or "git commit -a")
So far, so good. The directory was no longer listed, but the files were of course gone too. I could have restored them from my backup, but this is what Git was made for:
到现在为止还挺好。该目录不再列出,但文件当然也不见了。我本可以从备份中恢复它们,但这就是 Git 的用途:
rex@sidekick> git checkout -- app/models/xSpecific/GetAddressesLog.java
rex@sidekick> git checkout -- app/models/xSpecific/GetProductLog.java
rex@sidekick> git status
# On branch master
# Your branch is ahead of 'origin/master' by 10 commits.
#
nothing to commit (working directory clean)
Time to celebrate! Actually, it would probably have been easier to just clone off a new copy of the repository and use that instead, but by doing it the hard way I learned something new :).
是时候庆祝了!实际上,克隆存储库的新副本并使用它可能会更容易,但是通过这样做,我学到了一些新东西:)。
回答by Robert Childan
This solved the problem for me rm .git/fs_cache
这为我解决了问题 rm .git/fs_cache
回答by Sikander Bhutto
Same issue i got and i solved
我遇到了同样的问题,我解决了
git clean -f -n
回答by kelvin
I had important untracked files and couldn't just run git clean -f
as some
answers suggest.
我有重要的未跟踪文件,不能git clean -f
像某些答案建议的那样运行。
I try to add the directory and re-check the status.
? git add rosetta_tests/profile/tests/docking/
我尝试添加目录并重新检查状态。
? git add rosetta_tests/profile/tests/docking/
And it seems that adding a whole directory does not trigger a file recheck.
并且似乎添加整个目录不会触发文件重新检查。
So I tried adding specificallyone of the supposedly untracked files and it worked:
所以我尝试专门添加一个据称未跟踪的文件,它起作用了:
$ git status
On branch foo
Untracked files:
(use "git add <file>..." to include in what will be committed)
important.txt
foo/foo.java
foo/bar.java
foo/baz.java
foo/qux.java
nothing added to commit but untracked files present (use "git add" to track)
$ git add -- foo/foo.java
fatal: pathspec 'foo/foo.java' did not match any files
$ git status
On branch foo
Untracked files:
(use "git add <file>..." to include in what will be committed)
important.txt
nothing added to commit but untracked files present (use "git add" to track)
回答by J E Carter II
This error popped up for me when git add
failed due to a file name being too long in a sub directory. (in my case, something in node_modules)
git add
由于子目录中的文件名太长而失败时会弹出此错误。(在我的情况下,node_modules 中的某些内容)
In this case, adding a .gitignore file with content of *
to the node_modules folder allowed git add to run to completion.
在这种情况下,将内容为 的 .gitignore 文件*
添加到 node_modules 文件夹允许 git add 运行完成。
So, pay attention to the command output of git add .
(or -A or --all) and make sure it is not stopping prematurely due to an error. All of my "untracked" files and folders were added successfully once the proper .gitignore was applied and I was able to commit and push my changes.
因此,请注意git add .
(或 -A 或 --all)的命令输出,并确保它不会因错误而过早停止。一旦应用了正确的 .gitignore 并且我能够提交和推送我的更改,我所有的“未跟踪”文件和文件夹都已成功添加。