Git diff for branches’ starting point

Viewed 75

Assuming I'm on branch foo, I use git difftool main.

If I pull main to the latest, then that diff changes. However, if push up the PR to GitHub I see the diff I expect.

What is the command to say git difftool main-at-the-SHA-where-I-started-this-branch?

1 Answers

If you want to view locally the same diff as the one you see in your PR, you need to run :

git difftool main...foo  # 3 dots, not a typo

The 3 dots notation for git diff is explained in the doc :

This form is to view the changes on the branch containing and up to the second , starting at a common ancestor of both . git diff A...B is equivalent to git diff $(git merge-base A B) B. You can omit any one of <commit>, which has the same effect as using HEAD instead.

It will show you the diff of your branch since it forked from main -- as opposed to the diff between your branch and the current state of main, which may change if other branches are merged.

Related