Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to commit a long Git merge in the middle of resolving conflicts

I have a big merge going on with over 300 conflicting files. I want to resolve these using mergetool, but there's no way I'm going to finish it all in one sitting. How can I commit the merge and then come back later and continue the same merge? Normally it seems git doesn't allow you to commit if there are conflicts in the index.

like image 635
Reed G. Law Avatar asked Feb 14 '11 20:02

Reed G. Law


1 Answers

I'm assuming by "can't do it in one sitting" you actually mean "want to do some other things before I finish" - since you could just leave the partially resolved merge in your work tree otherwise.

First, before you go to any trouble, note that you could simply create another clone of the repository - the partially resolved merge can stay in one, and you can do other work in another.

All that said, if you really do want to save the work you've done to partially resolve a merge, my best suggestion is to use git rerere (REuse REcorded REsolutions).

To get started, make sure that rerere.enabled is set to true - that will cover most of the normal use cases. It causes git rerere to automatically be run immediately after merge conflicts happen - at that point you will see messages of the form Recorded preimage for '<path>'. It's also run automatically when you commit a merge; then you'll see messages of the form Recorded resolution for '<path>'.. The resolutions can then be reused later when the same conflicted hunks appear.

Now, in your use case, the first automatic trigger will happen - the preimages will be recorded. But you're not ready to commit your merge, so after resolving some conflicted files and marking them as resolved (adding them to the index) you can instead run git rerere (no arguments) directly. It will record the resolutions for everything you've marked as resolved, but ignore whatever's still unresolved. You can then simply destroy the attempted merge (git reset --merge), and the next time you attempt it, the recorded resolutions will be reused!

like image 89
Cascabel Avatar answered Sep 20 '22 13:09

Cascabel