我正在对我要删除的第二个文件执行此命令(第一个是 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.
那么当 git 没有列出它们时,我怎么知道 git 指的是什么“未暂存”文件,我该如何解决这个问题?
PS 问题不是 stash ,我没有也没有在这个 repo 上做过任何 stash 。
注意:我做了一个 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)
最佳答案
啊哈!!我知道发生了什么事。阅读最后几句话以获得一点洞察力。
答案是先做:
git status
这以红色显示修改后的文件,我认为这意味着它们在 git 的脑海中以某种方式“删除”了。然后我做了:
git add --all
从那里我使用 SourceTree 提交了所有暂存文件(抱歉我没有一直使用命令行)。我继续并同时将更改推送到服务器,但这是可选的。
然后上面的命令成功运行。
当我尝试在不同的文件上运行上述命令时,我遇到了同样的问题。所以我再次运行 git status
,结果发现我刚刚从历史记录中删除的文件仍然在那里,所以你需要这样做:
git rm /previous_file_you_just_removed_from_history.php
还要澄清一下,filter-branch 命令将从所有提交中删除该文件的历史记录,但它不会删除您对该文件所做的更改。 IE。删除的文件仍然是您到那时为止对其所做的所有更改的总和。我希望这有助于为其他人理清这个概念。
关于git 说我有未暂存的更改,但我看不到它们,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/41554303/