Search code examples
gitgit-stashmerge-conflict-resolutiongit-merge-conflict

Git - how to stash away a conflict and resolve it later


I merged one branch into another and ran into a conflict. I resolved it partially, but I need help from a colleague to finish resolving it. In the meantime, while I'm waiting for him, I want to stash away this conflict and continue working on something else. But I don't want to lose progress on what I already resolved.

What should I do? Is there a way to accomplish this, apart from cloning the repo again in another directory or manually copying over the conflicted file and then copying it back later?

If I try to simply stash it, git complains like so:

path/to/file/with/unresolved/conflict: needs merge
path/to/file/with/unresolved/conflict: needs merge
path/to/file/with/unresolved/conflict: unmerged (somesha)
path/to/file/with/unresolved/conflict: unmerged (somesha)
path/to/file/with/unresolved/conflict: unmerged (somesha)
fatal: git-write-tree: error building trees
Cannot save the current index state

Solution

  • Enable rerere in your repository:

    $ git config rerere.enabled true
    

    Solve all the conflicts you can, then abort the merge operation (git merge --abort). All the successful conflicts resolutions will be registered by rerere and replayed later automatically for the same conflicts.

    See this blog entry: https://git-scm.com/blog/2010/03/08/rerere.html