What to do if git-am fails with "does not match index"?

Viewed 29129

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?

2 Answers

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

"

Related