每次我在该 git 存储库中提交任何内容时,都会收到一条(显然是无害的)错误消息,其中提到了一些不再存在的文件:
$ git commit -a
error: Could not open cssrc/csgrpc/Main.cs
error: Could not open cssrc/csgrpc/Main.cs
Recorded preimage for 'cssrc/csgrpc/Main.cs'
... more 3-line groups like one above ...
[x017-upgrade a86861b] Point Audio to new location of....
1 file changed, 1 insertion(+), 1 deletion(-)
Run Code Online (Sandbox Code Playgroud)
这些文件最初是子树的一部分,用 维护git subtree -P cssrc ...,我在git subtree pull冲突期间删除了它们,因为在这个项目中不再需要它们(但之前被修改并提交,因此发生冲突)。
这些文件确实既不在索引中也不在工作树中:
$ git ls-files -cs | grep Main.cs
$ find -name 'Main.cs'
$
Run Code Online (Sandbox Code Playgroud)
该rerere.enabled选项设置为true。它是罪魁祸首吗?指向这些文件名的卡住指针存储在哪里?如何清洁?
错误的来源是 gitrerere或 xe2x80x9creuse 记录的解析 xe2x80x9d 功能。由于您“在”期间删除了它们(您的文件)git subtree pull conflict,因此您无意中将 git 置于“未解决”状态。git rerere尽最大努力保留干净的冲突解决记录,以便以后重复使用。因为您在冲突解决过程中删除了文件,所以您在 中引用了这些文件rerere,导致 git 查找不再存在的文件。了解为了让 git 重用记录的解决方案,它必须记录所涉及的步骤。但是,这并不意味着 git 正在跟踪您使用的命令;而是意味着 git 正在跟踪您使用的命令。这解释了为什么它不知道为什么处于冲突状态的文件在其已解决状态中丢失。它希望您选择该文件的一个版本或另一个版本,而不是完全删除该文件。
如果您有兴趣了解更多信息,git rerere我建议您阅读git 手册页。
如果您对此问题中描述的问题的工作示例以及该问题的解决方案(我确信还有更多)感兴趣,请按照下面列出的步骤操作。我知道它很长,但我不知道还能如何澄清这个问题。
\n\n在适合测试代码的目录中...
\n\n$ mkdir test_rerere$ cd test_rerere$ git init$ cd .git$ mkdir rr-cache$ cd ..使用以下代码创建一个名为 hello.rb 的文件
\n\n#! /usr/bin/env ruby\n\ndef hello\n puts \'hello world\'\nend\nRun Code Online (Sandbox Code Playgroud)$ git commit -a -m"added hello.rb"使用以下代码创建名为 goodbye.rb 的文件
\n\n#! /usr/bin/env ruby\n\ndef bye\n puts "goodbye world"\nend\nRun Code Online (Sandbox Code Playgroud)$ git commit -m"added goodbye.rb"$ git branch i18-world$ git commit -a -m"changed hello to hola in hello.rb"$ git checkout i18-world$ git commit -a -m"changed world to mundo in hello.rb"$ git commit -a -m"changed goodbye to adios in goodbye.rb"$ git checkout master$ git commit -a -m"changed world to mundo in goodbye.rb"\n现在我们有两个分支,有两个相似但不相同的文件。花一点时间查看两个分支中存在的每个文件。$ git status应该说
On branch master\nnothing to commit, working tree clean\nRun Code Online (Sandbox Code Playgroud)$ git merge i18-world你应该得到看起来像这样的东西......
\n\nAuto-merging hello.rb\nCONFLICT (content): Merge conflict in hello.rb\nAuto-merging goodbye.rb\nCONFLICT (content): Merge conflict in goodbye.rb\nRecorded preimage for \'goodbye.rb\'\nRecorded preimage for \'hello.rb\'\nAutomatic merge failed; fix conflicts and then commit the result.\nRun Code Online (Sandbox Code Playgroud)$ git rerere status返回 goodbye.rb 和 hello.rb,因为正在记录此冲突的两个文件。现在不是尝试的好时机,git rerere diff现在git ls-files -u让我们创建一个错误状态。hola mundo,并且在不提交的情况下,让$ git rm goodbye.rb. 这会导致你的错误。看一下$ git status,goodbye.rb 确实已被删除(尽管 git 抱怨)并且 hello.rb 已被修改并准备合并。$ git commit -a -m"HUH?"$ git log --oneline --decorate --graph --all查看我们提交历史的漂亮图片。$ git commit -a -m"changed \'hola mundo\' to \'hola chica bonita!\' in hello.rb"$ git rerere status仍然应该返回goodbye.rb,因为它仍然记录在原像中。$ git rerere diff返回致命错误,因为 goodbye.rb 不存在。$ git log --oneline --decorate --graph --allgit status和git rerere status不会返回相同的结果。请确保您的工作目录中不存在 goodbye.rb,以确保您的理智。$ git checkout **yoursha1** goodbye.rb。git rerere……哒哒!请注意,git 说“Recorded resolution for \'goodbye.rb\”。$ git checkout i18-world$ git rebase master$ git status回报nothing to commit, working tree clean$ ls返回“hello.rb”,所以我们知道我们已经摆脱了那个讨厌的 goodbye.rb 文件。$ git log --oneline --decorate --graph --all向我们展示了我们所有的辛勤工作。$ git rerere status不返回任何内容,因为没有任何内容被跟踪(没有原像)。$ cat hello.rb向我们展示
#! /usr/bin/env ruby\n\ndef hello\n puts \'hola chica bonita!\'\nend\nRun Code Online (Sandbox Code Playgroud)$ git commit -a -m"updated hello in hello.rb to say \'hola chica bonita! te amo"git log --oneline --decorate --graph --all看到i18-world领先于master。$ git checkout master$ git merge i18-world$ git branch应该返回i18-world *master$ git branch -d i18-world您现在可以确信您的工作目录是干净且没有错误的。另外,如果您需要回到存在“goodbye.rb”的状态,您可以!
\n\n我对这个答案的长度表示歉意,但希望现在您了解问题出在哪里,以及修复它们是多么容易(至少在这个小示例中)。
\n