53

After branches are merged, and GitHub no longer show difference when I try to make a pull request, but git diff will still show differences.

For example:

  1. I have branch D
  2. Created hotfix on branch H
  3. Merged H to D
  4. Created more stuff on D

Now GitHub pull request from H to D shows no difference but git diff H D show differences.

What I am trying to do is to create a command-line tool to see which old branches (there can be a lot) don't have code differences to develop. right now I have to go to GitHub, do a pull request and select each branch to see if there are difference.

Seanny123
  • 8,776
  • 13
  • 68
  • 124
Gary
  • 533
  • 1
  • 4
  • 4
  • 1
    You might want to take a look at "git branch --merged". It will show you all branches that have been merged into the current branch. – John Szakmeister Jun 11 '16 at 12:45

2 Answers2

57

You probably want the "triple-dot" syntax:

git diff D...H

See also What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?

Community
  • 1
  • 1
Oliver Charlesworth
  • 267,707
  • 33
  • 569
  • 680
  • 5
    When I needed to use this, order matters I have master as first input and my feature branch as second – user1821961 Aug 20 '18 at 17:14
  • Wouldn't it be the "double-dot" syntax? Github probably shows only the introduced changes from branch H not present in D. The "triple-dot" shows everything different in both branches. – Spidey Feb 21 '19 at 13:02
  • 2
    This appears to be the best explanation of the 3-dot syntax: https://stackoverflow.com/a/7252067/4561887. I've also left a comment under that answer. `git diff D...H` appears to be equivalent to `git diff $(git merge-base D H) H`, which is what I've always used in the past. – Gabriel Staples Sep 09 '20 at 19:45
  • Another way to read this: `git diff develop...hotfix` or `git diff merge-destination...branch-to-merge` – phyatt Apr 20 '22 at 16:38
-1

What I am trying to do is to create a command-line tool to see which old branches (there can be a lot) don't have code differences to develop.

SUMMARY: Any of these work to test your quoted desire above:

# ALL OF THESE APPROACHES BELOW **WILL HAVE BLANK OUTPUT**
# if H has no changes added since it was last forked
# off of D

# Look for **changed lines** on H since it was last forked off of D
git diff D...H
# Exact same thing as above, as this is what the 3-dot syntax does 
# under the hood:
git diff $(git merge-base D H) H
# Exact same thing as above (using the 2-dot syntax)
git diff $(git merge-base D H)..H

# Look for **added commits** on H which don't exist on D
git log --oneline --no-merges H ^D

Further explanation of this style of git log cmd:

git log --oneline --no-merges feature_branch ^develop

This shows all commits (excluding merges) in a one line format which are on feature_branch but are NOT (as indicated by the ^) on the develop branch. Similar to git diff or git difftool, if there are no changes (commits in this case) to display, the output is blank.

References:

  1. This answer: What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?

  2. Another answer: What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?

  3. My own notes on the git log H ^D style cmd above: I have more examples in my dotfiles project here. Ex:

    FIND ALL GIT COMMITS WHICH ARE ON ONE BRANCH BUT NOT ON ANOTHER!
    [keywords: git commits on one branch but not another, git commits not on branch, git commits in one branch but not another]

    1. git log --no-merges branch1 ^branch2 ^branch3
      show all commits which are ONLY on branch1, but NOT on branch2 or branch3, omitting all merge commits since they aren't new changes! See: Using Git, show all commits that are in one branch, but not the other(s) <========== SUPER USEFUL TO SEE WHAT CHANGES A BRANCH CONTAINS ON IT! ============ This is VERY USEFUL to see, for instance, what are all of the feature commits we've added to a long-running release branch named "branch1", into which which we have periodically been merging the latest master. Now, we can see which commits are in any given branch but not in master! Ex:
    2. git log --no-merges branch1 ^master
      show all NON-merge commits in branch1 which are NOT in master!
    3. git log --oneline --no-merges branch1 ^branch2 ^branch3
      same as above, but show only one line per commit! <======= EXCELLENT! (& SIMPLEST) ========
    4. git lg --no-merges branch1 ^branch2 ^branch3
      same as above, but using the git lg git alias instead, to show condensed (one-line) output with extra information! <======= BEST! (perhaps) ========

    git lg from above comes from here: https://coderwall.com/p/euwpig/a-better-git-log. To "install" it as a git alias, simply run:

     git config --global alias.lg "log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit"
    

    It's super useful!

E_net4
  • 27,810
  • 13
  • 101
  • 139
Gabriel Staples
  • 36,492
  • 15
  • 194
  • 265