When applying a patch is there any way to resolve conflicts?

GitGit AmGit Apply

Git Problem Overview


I am on windows.

For various reasons we have multiple git instances of different svn branches.

Many times I want to fix an issue in repository A, generate a patch, and apply it to repository B. This works fine except if there are conflicts.

When rebasing I just right click the folder and use tortioseGit and select the resolve option. This brings up a nice gui to let me work through my conflicts.

Is there any way to accomplish this with rejected patch chunks?

Here is my current approach to creating/applying the patches

git format-patch master --stdout > c:\\patch\\file.patch
git apply --reject --ignore-space-change --ignore-whitespace c:\\patch\\file.patch

Git Solutions


Solution 1 - Git

To generate your patch do the following:

git format-patch --stdout first_commit^..last_commit > changes.patch

Now when you are ready to apply the patches:

git am -3 < changes.patch

the -3 will do a three-way merge if there are conflicts. At this point you can do a git mergetool if you want to go to a gui or just manually merge the files using vim (the standard <<<<<<, ||||||, >>>>>> conflict resolution).

Solution 2 - Git

If you are frequently running into the same conflict set when applying patches, rebasing or merging then you can use git rerere (reuse recorded resolution) function. This allows you to pre-define how conflicts should be resolved based on how you resolved them in the past. See http://git-scm.com/blog/2010/03/08/rerere.html for details of how this works.

Solution 3 - Git

TortoiseGit has a merge feature that can open patch files.

There's a picture of it here.

Solution 4 - Git

My approach is:

  • Create an "Integration"-Branch where the files are identical
  • Apply the patch to this Integration-Branch
  • Merge or rebase it to master (don't know if rebase is useful here, because I don't know what will happen when applying further patches)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionKenoyer130View Question on Stackoverflow
Solution 1 - Gitg19fanaticView Answer on Stackoverflow
Solution 2 - GitmproffittView Answer on Stackoverflow
Solution 3 - GitamsView Answer on Stackoverflow
Solution 4 - GitMichiBackView Answer on Stackoverflow