Search code examples
gitgit-mergegit-diff

How to apply diff between commits to current head in git?


I was working on some topic branch on project I participate in. I normally rebase my branches before making a pull request. This time however, due to changes in master, rebasing is a big pain. Lot of conflicts and, what's worse, after manual merging commits look just ugly and loose their point. I would definitely prefer to obtain diff between my branch's head and latest commit present on both branches, then apply this diff to master's head and finally create brand new shiny commits with git add -p. So my question is: how to achieve it? One possibility would be to simply merge master into my topic branch, but is there a more elegant solution? I believe yes.

Thanks for your help.

EDIT:

One file has been moved on master branch and my commits are altering this file (using it's old name).


Solution

  • Use git cherry-pick --no-commit <commit>...

    Then you will get all the changes in the listed commits applied on the top of your branch, and you can commit at your leisure.


    If you have a more complicated use case, you might want to try git imerge

    Its creator made an introduction blog post and a presentation about it. Both a bit old unfortunately.