1

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?

mkrieger1
  • 19,194
  • 5
  • 54
  • 65
Kirk Strobeck
  • 17,984
  • 20
  • 75
  • 114
  • Take a look at `main`'s local reflog (with `git reflog main`). If no other operations happened on the branch other than the pull you described, you should find current SHA (after the pull) referenced `main{0}`, the previous SHA (the one you look for) should then be `main@{1}`, and so on for older positions of the local branch. – Romain Valeri Feb 02 '22 at 20:32

1 Answers1

3

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.

Kirk Strobeck
  • 17,984
  • 20
  • 75
  • 114
LeGEC
  • 46,477
  • 5
  • 57
  • 104
  • actually i just tried this in another place and it did not work – any idea why? im getting a massive diff – Kirk Strobeck Feb 07 '22 at 22:09
  • run `git log --graph --oneline a...b` and check if the list of commits you see is the one you expect. Run `git log --graph --oneline a b` (no dots) to have a complete view of both branches. – LeGEC Feb 08 '22 at 17:58