diff-and-compare
| notation | meaning |
|---|---|
| HEAD, --ours | currently checked out branch |
| feature, origin/.. --theirs | other branch |
merge-base
common ancestor of two branches
git merge-base main feature
triple dots (...)
(see also 3diff)
compares the common ancestor of a and b with b.
(This is different from the "double dots" (..).)
# changes in b compared to ancestor of a & b
git diff a...b
# with main checked out
# show the changes in feature
git diff HEAD...feature
# show the changes in _our_ branch (main)
git diff feature...HEAD
diff3-style merge conflicts
Not only show ours and theirs, but the common ancestor as well. This helps to decide about the intent of a changes.
set via command line
git config --global merge.conflictstyle diff3
or in .gitconfig
[merge]
conflictstyle = diff3
An example merge conflict now looks like this.
<<<<<<< HEAD
initial content
add more content on main
||||||| parent of 2deebc8 (added some more content)
initial content
=======
initial content
additional content added
>>>>>>> 2deebc8 (added some more content)
| section | |
|---|---|
| HEAD | current head of main (with potential new changes) |
| parent of 2deebc8 ... | where the branch got of off main (common ancestor) |
| 2deebc8 | commit on the branch to be merged |
patch for (rebased) feature compared to main
# on feature, to get latest main
git rebase -i main
git diff main > feature.patch
# apply: on main (git switch main)
patch -p1 < feature.patch
git add .