Itzik984
Itzik984

Reputation: 16794

Error on git patch using git am

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?

Upvotes: 4

Views: 3694

Answers (2)

Claudio
Claudio

Reputation: 10947

You need to do a 3-way merge:

  git am -3 0001-someFile.patch

  git mergetool -t meld

Upvotes: 0

John Woodruff
John Woodruff

Reputation: 1666

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.

Upvotes: 1

Related Questions