Reputation: 81
To merge two divergent branches (say I'm on master
and want to merge topic
), sometimes it's easier to manually merge files by inspecting git diff
and applying the changes manually (or parts of them automatically using git apply
). However, this just changes the working directory files, so my commit will just have current master
as a parent commit, rather than appearing as a merge commit between master
and topic
. Is there a way to manually specify parent commits to git commit
?
Upvotes: 1
Views: 487
Reputation: 81
torek's comment indeed is closest to what I'd prefer:
git commit-tree -p <parent1> -p <parent2> -m <message> $(git write-tree)
This outputs a new commit hash, that I can use with git reset --hard <hash>
to get my desired result.
Upvotes: 5
Reputation: 60255
The pure handroll setup is
git merge -s ours --no-ff --no-commit otherbranch
which sets the parents for whatever you commit as the result and leaves all the actual merging to you. If doing touch-up on the automerge will work better for you, leave off the -s ours
.
Upvotes: 1