brewedbits.dev

Personal blog with guides and news on selfhosting, Linux and AI, from the Netherlands

nextDash nextdash --aboutYour bookmarks. Your terminal. checks your links knows your Docker host one container, no cloudLive demo →nextdash.cc ↗

Tip: git diff with three dots shows only what your branch changed

Git
~/tips/tip-git-diff-three-dots-branch

git diff main...feature

Compares your branch with the point where it left main, so other people's work stays out.

Two dots and three dots look almost the same in git diff, but they answer different questions. For reviews I’d nearly always want three.

git diff main...feature

With three dots, git compares feature with the merge base of the two branches, the commit where feature split off. You see only the changes made on the branch, which is what a pull request shows.

With two dots, git diff main..feature is the same as git diff main feature: a straight comparison of the two tips. If main moved on after you branched, all those newer main commits show up as if your branch removed them. That catches you out if you forget.

Combine it with --stat for a quick overview before you open the full diff:

git diff --stat main...HEAD

One thing that trips people up: in git log the dots mean something else. There, main..feature lists commits on feature that aren’t on main, and three dots list commits on either side but not both. Only git diff uses three dots for “since the merge base”. The docs even say the dotted forms of git diff don’t really describe ranges.

Further reading: git-diff documentation

More Git tips git show-branch main feature git log --stat -5 git merge --no-ff feature -m "Merge feature" git merge --squash feature git merge --abort All Git tips (144) All topics

Link