Git Interactive Merge?
As per this gist, where temp could be an existing branch.
https://gist.github.com/katylava/564416
On master:
git checkout -b temp
On temp:
git merge --no-commit --no-ff refactor
… which stages everything, so:
git reset HEAD
Then begin adding the pieces you want:
git add --interactive
Yes, but it will mostly be by manually making that happen. You'll tell Git you're merging the two relevant branches, but that it shouldn't try to commit the result on its own, (edited to add: nor fast-forward if it thinks the merge is trivial):
git merge --no-commit --no-ff branch-to-merge
Then you'll ask git for the file as it appeared in the two branches:
git show HEAD:filename >filename.HEAD
git show branch-to-merge:filename >filename.branch
and their merge base,
git show `git merge-base HEAD branch-to-merge`:filename >filename.base
You'll merge them using whatever tool you want (e.g.)
meld filename.{HEAD,branch,base}
you'll stage that (git add filename
), and then commit the merge (git commit
).
From the branch you want to merge into:
git checkout -p branch_to_merge --
This won't checkout the branch_to_merge, but will let you interactively add hunks from the patch (diff).
http://git-scm.com/docs/git-checkout
The easiest way is to do git merge <other_branch
then git mergetool
to graphically resolve the conflicts. See #10935226 for how to set up mergetool.
The hitch is, your changed file may fast-forward merge with with the older one. Then you have to get a bit more clever.
Novelocrat gives a great way to dig a bit deeper, but you will often have to change the initial command to git merge --no-commit --no-ff <other_branch>
because --no-commit really means "Don't commit the merge...unless it's a fast-forward merge." It's a bit of a stinger for lots of folks trying to do exactly what you want.
Sometimes the least confusing way is not very stylish: check out the other branch in a different working copy, use your favorite merge tool to get the version you want in the directory you want, then commit it.