When using git, it seems to be a good idea to fetch
and merge
(as pointed out in this blog) instead of just pulling in order to allow yourself to view the changes before merging.
This seems a reasonable and safe way to do things and I can follow so far.
However, what if I then do a git diff
between master and origin/master and decide that most of the updates are good, but a couple of things need fixing? Is there a way to "manually" merge? I am looking for something similar to the editing that you get after a merge conflict which lets you decide on each single change - a little bit like git add --patch
.
What I want is to have the power of editing things before merging origin/master into my own master, ideally with my favourite difftool
.
I understand this could be done by applying the changes to master
and then force pushing it with git push -f
, but this seems a little brutal and unnecessary.
On the other hand, cherrypick
sounds like a very promising name, but only allows to select commits, not actual changes on files.
How can one do a highly selective/manual merge? None of the merge strategies from the docs seems to allow enough manual control for this.
The moment you do the merge, use the parameter --no-commit
.
git merge --no-commit <branch>
This will stop the merge at the time of creating the commit, leaving your status as a pending merge, which is exactly the same as when a conflict happens.
From this status, you can diff and make the necessary changes.