0

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?

Mark
  • 31
  • 4
  • Besides jthill's answer, you can also go much lower level and run `git write-tree`, `git commit-tree`, and `git update-ref` manually. – torek Sep 28 '22 at 14:07

2 Answers2

1

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.

Mark
  • 31
  • 4
0

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.

jthill
  • 55,082
  • 5
  • 77
  • 137