Wednesday, April 21, 2010

I just found an awesome way to merge git patches with opendiff

Have you ever been in the situation that someone sent you a patch and you want to take some things from it but probably not all and you definitely want to check each change before accepting that? If you have worked with git, off course you have.

There are many ways of doing this. However maybe you have a favorite merge tool? For me this was open-diff which can show my old version to the left, the new version which I got from someone to the right and the current merge of them at the bottom. I can also edit the bottom one and write whatever I want there. In other words an awesome tool for doing manual merging and adopting of some but not all changes which have been sent to you. It took me a while (and some help from #git on freenode) to figure out how to use open diff for this but in the end it was well worth it.

This is how you can do it:

1. Create a new branch and apply the patch. Copy the #hash it get.

2. Checkout the branch you want to apply the merged commit to.

3. Write: git diff-tool -t opendiff #hash

This will open the opendiff tool for your original compared to the new version and when saving you can overwrite you original files and commit as usual.