2010-08-26 187 views
12

我正尝试应用由其他人创建的git补丁git-format-patch。这个补丁是针对HEAD后面的一个提交而做出的,但据我了解,这应该不重要。当我运行git am 0001.patch,我得到的错误:如果git-am与“不匹配索引”失败,该怎么办?

error: source.c: does not match index

我不是太熟悉的git补丁的格式,但它似乎该指标不匹配,但源不匹配。

解决此问题的最佳方法是什么?手动更改索引以匹配?或者我应该git-apply,然后在我提交时复制作者和描述信息?

回答

11

J.C. Hamano (Git maintainer) himself,这是关于:

patch applications and merges in a dirty work tree with a clean index.

  • A dirty work tree is where you have changes that are not added to the index.
    A work tree that is not dirty is a clean work tree.
  • A dirty index is where you have changes already added to it (in other words, " git diff --cached " will report some changes).
    A clean index matches the HEAD.

随着最近的Git版本中,可以中止:

To restore the original branch and stop patching run " git am --abort ".

然后:

The simplest thing for those who cannot decide may be to stash the changes away for later.

$ git stash save "Random changes that are not ready" 

And then redo " git pull " or " git am ".
" git stash " is the ultimate tool for people who are afraid of commitment.

After redoing " git pull " or " git am ", you can replay the local changes you stashed away:

$ git stash pop 

注:脏树的一个来源可以是autocrlf设置(如在此msysgit issue 81),所以要sure to set that to false
其他来源的差异:core.whitespace setting


的OP提到的评论:

Before trying to run git am I did run git stash , so I don't think that was the problem.
What I ended up doing was running git am -3 patch.patch, then manually fixing the problem, then running ' git am --resolved '.

注:最近Git1.7.2 Release Notes

The message from " git am -3 " has been improved when conflict resolution ended up making the patch a no-op.

+0

感谢您的答复。我在尝试运行'git am'我没有运行'git stash',所以我不认为之前那是问题。我最终什么事做的是运行'git am的-3 patch.patch',然后手动修复问题,然后运行'git am --resolved'。 – joshdoe 2010-08-26 20:15:38

+0

@joshdoe:非常感谢您的反馈,我已经将它包含在答案中。 – VonC 2010-08-26 20:23:12

1

对我,我的是较旧版本的git版本(CentOS-6发行版)。

我可以做来解决该问题:

  • git update-index --refresh
  • git am ${patch_filename}

阅读更多关于为什么这个工程。请the original source here

我有点惊讶的是,我们没有做的‘刷新一次的前期’ 已经和没有人碰到这种在过去的5年似乎 我继承了。来自git-applymbox ;-)的行为

在开始时重新刷新一次,以及使用“am -resolved”重新启动 是明智的。

+0

我尝试了最新的答案,但didn 't为我工作'git update-index --refresh'命令为我制作了一个技巧。 – mask 2018-03-06 18:53:12

相关问题