4

When I try to perform a patch using:

git am 0001-someFile.patch

but I get this error:

error: patch failed: src/***/file.c:459
error: src/***/file.c: patch does not apply
Patch failed at 0001 someFile.patch
When you have resolved this problem run "git am --resolved".
If you would prefer to skip this patch, instead run "git am --skip".
To restore the original branch and stop patching run "git am --abort".

I am trying to manually merge the conflicts using:

git mergetool --tool=meld

But I am getting:

No files need merging

How can I solve this problem? I am getting the name of the file which holds the error, but have no idea about the line (it's a big file)

Maybe there is a better way to perform such patching?

Claudio
  • 10,614
  • 4
  • 31
  • 71
Itzik984
  • 15,968
  • 28
  • 69
  • 107
  • What does `git status` tell you? Does it show any unmerged entries? If it doesn't, then supposedly the patch is so "unapplicable" that it fails not because there are any merge conflicts but because all the hunks simply fail to apply -- for instance, no context can be found for each of them. – kostix Jun 15 '13 at 18:12

2 Answers2

1

I'm in charge of handling all patching at my work. I've had this happen many times. A patch cannot be merged. The reason this is happening is because the master branch has changes that the patch did not take into account, which prevents it from patching correctly. From all my experience, this could be caused by several things:

  • The person who made the patch failed to pull the master branch and rebase master onto their development branch.
  • Between the time that the person pulled and the patch was applied enough changes were made to the master branch to stop the patch from applying due to too many conflicts.
  • The person patched incorrectly.

Here is the flow I've had the most success with. (This is assuming the person is developing on a branch other than master)

  1. Make sure you've added all files and commited all changes.
  2. git checkout master
  3. git pull
  4. git checkout {development branch}
  5. git rebase master (this will bring the development branch up to speed with master)
  6. git checkout -b {submission branch} master
  7. git merge --squash --no-commit {development branch}
  8. git commit -am "Commit Comment Here" (NOTE: This commit comment will be the name of the patch)
  9. git format-patch origin..HEAD

That makes sure your patch is up to date with the origin master branch. Send that patch and hopefully the patch is applied before too many changes are made on the master.

John Woodruff
  • 1,608
  • 16
  • 29
0

You need to do a 3-way merge:

  git am -3 0001-someFile.patch

  git mergetool -t meld
Claudio
  • 10,614
  • 4
  • 31
  • 71