如果 git-am 因“不匹配索引”而失败该怎么办?

发布于 2024-09-16 06:32:52 字数 293 浏览 1 评论 0原文

我正在尝试使用其他人使用 git-format-patch 创建的 git 补丁。该补丁是针对 HEAD 后面的一次提交而制作的,但据我了解,这应该不重要。当我运行 git am 0001.patch 时,出现错误:

error: source.c: does not match index

我不太熟悉 git 补丁的格式,但索引似乎不匹配,但源确实匹配。

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

I'm trying to apply a git patch created by someone else with git-format-patch. The patch was made against one commit behind HEAD, but as I understand it this shouldn't matter. When I run git am 0001.patch, I get the error:

error: source.c: does not match index

I'm not too familiar with the format of git patches, but it does seem that the indexes don't match, however the source does match.

What's the best way to fix this? Manually change the indexes to match? Or should I git-apply and then copy the author and description information when I commit?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-09-23 06:32:52

来自JC Hamano(Git 维护者)本人,内容是:

修补应用程序并合并到具有干净索引的脏工作树中。

  • 脏工作树是指您所做的更改未添加到索引中的位置。
    不脏的工作树就是干净的工作树。
  • 脏索引是您已添加更改的位置(换句话说,“git diff --cached”将报告一些更改)。
    干净的索引与 HEAD 相匹配

在最近的 Git 版本中,您可以中止:

要恢复原始分支并停止修补,请运行“git am --abort”。

然后:

对于那些无法决定的人来说,最简单的事情可能就是将更改保存起来以供以后使用。

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

然后重做“git pull”或“git am”。
git stash”对于那些害怕承诺的人来说是终极工具

重做“git pull”或“git am”后,您可以重播您隐藏的本地更改:

$ git stash pop

注意:脏树的来源之一可能是 autocrlf 设置(例如 msysgit 问题 81) ,所以请确保将其设置为 false.
其他差异来源: core.whitespace< /代码>设置


OP 在评论中提到:

在尝试运行 git am 之前,我确实运行了 git stash,所以我认为这不是问题所在。
我最终做的是运行 git am -3 patch.patch,然后手动修复问题,然后运行 ​​'git am --resolved '。

注意:在最近的 Git1.7.2 发行说明< /a>:

当冲突解决最终使补丁成为无操作时,来自“git am -3”的消息已得到改进。

From J.C. Hamano (Git maintainer) himself, this is about:

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.

With recent Git release, you can abort:

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

Then:

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

Note: one source of dirty tree can be the autocrlf setting (like in this msysgit issue 81), so make sure to set that to false.
Other source of discrepancy: core.whitespace setting.


The OP mentions in the comment:

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'.

Note: in the recent 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.

不及他 2024-09-23 06:32:52

对我来说,我使用的是旧版本的 git (centOS-6 distro)。

我可以通过执行以下操作来解决此问题:

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

以了解有关其工作原理的更多信息。请检查 原始来源在这里

我有点惊讶我们没有完成“预先刷新一次”
过去 5 年里没有人遇到过这种情况。看来
我从 git-applymbox 继承了这种行为;-)

在开始时和重新启动时刷新一次是明智的
与“am --resolved”。

for me i'm on an older versions of git (centOS-6 distro).

I was able to fix the issue by doing:

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

to read more on why this works. please check the original source here:

"

I am kind of surprised that we have not done the 'refresh once upfront'
already and nobody ever run into this for the past 5 years. It seems that
I inherited that behaviour from git-applymbox ;-)

It is sensible to refresh once at the beginning and also when restarting
with "am --resolved".

"

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文