Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fix git am -3 conflicts by hand

Tags:

git

There are several similar questions but none that concretely adresses this afaik:

I have a git repository whose initial commit adds all files contained in version 1.0 of a project, let's call it foo. All following commits add specific modifications to foo 1.0. I would now like to port the changes made to a specific subdirectory to another version of, foo 2.0. To do this I have first created a patch:

 git format-patch --stdout SOME_COMMIT_ID..HEAD -- subdir > subdir.patch

Since there have been changes in foo between versions 1.0 and 2.0 this patch does not apply cleanly on top of foo 2.0. That's fine, I would like to fix any conflicts by hand. But how do I git to actually let me do this? Common advice is to use:

git am -3 < subdir.patch

Which should perform a three way merge. But all this does is output a bunch of errors of the form:

error: patch failed: ...

And ultimately:

It does not apply to blobs recorded in its index.
Patch failed at 0001 commit SOME_COMMIT_ID
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

That does not help me, why won't git let me fix conflicts by hand?

like image 903
Peter Avatar asked Oct 24 '25 05:10

Peter


1 Answers

git am -3 < subdir.patch

Which should perform a three way merge.

It should, and it does, under a condition.

But all this does is output a bunch of errors of the form:

error: patch failed: ...

And ultimately:

It does not apply to blobs recorded in its index.
Patch failed at 0001 commit SOME_COMMIT_ID
hint: Use 'git am --show-current-patch=diff' to see the failed patch
When you have resolved this problem, run "git am --continue".
If you prefer to skip this patch, run "git am --skip" instead.
To restore the original branch and stop patching, run "git am --abort".

I'm not sure what that line It does not apply to blobs recorded in its index. above is doing in there, but this indicates that the patch failed either because the three-way merge itself failed, in which case git status will show some unresolved merge conflicts, or because, well, let me quote from the git am documentation here:

-3
--3way
--no-3way
      When the patch does not apply cleanly, fall back on 3-way merge if the patch records the identity of blobs it is supposed to apply to and we have those blobs available locally. --no-3way can be used to override am.threeWay configuration variable. For more information, see am.threeWay in git-config[1].

(emphasis mine). The blob information comes from the index lines, and your repository needs to have those blobs in it for -3 to do anything useful here. If you don't have a blob with the specified hash ID, you'll just have to hand-apply the entire patch: consider using git apply --reject and hand-editing.

like image 177
torek Avatar answered Oct 25 '25 20:10

torek



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!