In Git is there a way (or tool) to merge by comparing changes, not files?

76 views Asked by At

In Git the standard merge algorithms let you compare the final state of the files in the two branches, which means I have to remember or guess what the changes leading up to that point in both branches were.

Setting merge conflictstyle=diff3 in .gitconfig helps, by showing the common ancestor. However, I still have to do the diffs in my head – i.e. scan the different sections to figure out what changed between the ancestor and branch A, and between the ancestor and branch B, and then finally apply both to the ancestor, or apply one branch's changes to the other.

Is there a tool that would do this for me? I want to be able to compare changes that happened in one branch with the changes that happened in the other. Ideally the tool would also show me the commit messages of the changes I'm merging so I wouldn't have to guess the intent.

1

There are 1 answers

0
Greg Bacon On

git cherry and git patch-id may help you find what you are looking for.

The changeset (or “diff”) of each commit between the fork-point and head is compared against each commit between the fork-point and upstream. The commits are compared with their patch id, obtained from the git patch-id program.

Every commit that doesn’t exist in the upstream branch has its id (sha1) reported, prefixed by a symbol. The ones that have equivalent change already in the upstream branch are prefixed with a minus (-) sign, and those that only exist in the head branch are prefixed with a plus (+) symbol:

           __*__*__*__*__> <upstream>
          /
fork-point
          \__+__+__-__+__+__-__+__> <head>