git 说我有未暂存的更改,但我没有显示它们
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/41554303/
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 says I have unstaged changes but I do not show them
提问by Oliver Williams
I am executing this command on the second file I want to remove (the first was JetBrains' .idea folder files which are now in .gitignore), but I am not able to:
我在要删除的第二个文件上执行此命令(第一个是 JetBrains 的 .idea 文件夹文件,现在位于 .gitignore 中),但我无法:
git filter-branch --force --index-filter 'git rm --cached --ignore-unmatch gf5/console/basic.php' --prune-empty --tag-name-filter cat -- --all
Cannot rewrite branches: You have unstaged changes.
So how do I know what "unstaged" files git is referring to when it does not list them, and how do I fix this?
那么,当 git 未列出它们时,我如何知道它们所指的“未暂存”文件是什么,以及如何解决这个问题?
PS the issue is not stash(es), I do not have any and have not done any stashing on this repo ever.
PS 问题不是 stash(es),我没有,也没有在这个 repo 上做过任何 stash。
NOTE: I did a git status
and receive this:
注意:我做了一个git status
并收到了这个:
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: gf5/console/basic.php
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)
//(and a whole long list of files)
回答by Oliver Williams
AHA!! I figured out what is going on. Read the last few sentences for a little insight.
啊哈!!我想通了是怎么回事。阅读最后几句话以获得一点见解。
The answer was to first do:
答案是首先做:
git status
This showed modified files in RED, which I presume means they are somehow "deleted" in git's mind. I then did:
这显示了 RED 中的修改文件,我认为这意味着它们在 git 的脑海中以某种方式被“删除”了。然后我做了:
git add --all
From there I committed all the staged files using SourceTree (sorry I didn't stay with the command line all the way). I went ahead and simultaneously pushed changes up to the server but that would be optional.
从那里我使用 SourceTree 提交了所有暂存文件(对不起,我没有一直使用命令行)。我继续并同时将更改推送到服务器,但这将是可选的。
The above command then worked successfully.
然后上面的命令成功运行。
When I tried to run the above command on a different file, I had the same problem. So I again ran git status
and it turns out that the file that I just removed from history is still thereand so you need to do this:
当我尝试在不同的文件上运行上述命令时,我遇到了同样的问题。所以我再次运行git status
,结果我刚刚从历史记录中删除的文件仍然存在,所以你需要这样做:
git rm /previous_file_you_just_removed_from_history.php
Also to clarify, the filter-branch command will remove the history of that file from all commits, but it will NOT remove the changes that you made to that file. I.e. that removed file is still the sum of all changes you made to it up to that point. I hope this helps clear this concept up for someone else.
还要澄清一下, filter-branch 命令将从所有提交中删除该文件的历史记录,但不会删除您对该文件所做的更改。即,删除的文件仍然是您在此之前对其所做的所有更改的总和。我希望这有助于为其他人澄清这个概念。
回答by ArkTekniK
I had this same issue whereby all of my files were showing as modified right after a fresh clone and discovered the cause to be (in my case) that Tortoise Git was automatically modifying the line endings of every file on checkout and commit.
我遇到了同样的问题,我的所有文件在新克隆后都显示为已修改,并发现原因是(在我的情况下)Tortoise Git 在检出和提交时自动修改每个文件的行尾。
To prevent this behaviour, disable the AutoCrLf
setting under the repository settings window (Git
-> Config Source [Local]
-> AutoCrlf
) as described in this question.
为防止此行为,请禁用AutoCrLf
存储库设置窗口 ( Git
-> Config Source [Local]
-> AutoCrlf
)下的设置,如本问题所述。