68

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
9,45617 gold badges75 silver badges136 bronze badges
asked Jun 11, 2016 at 12:39
1
  • 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. Commented Jun 11, 2016 at 12:45

2 Answers 2

69

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?

answered Jun 11, 2016 at 12:46
Sign up to request clarification or add additional context in comments.

4 Comments

When I needed to use this, order matters I have master as first input and my feature branch as second
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.
This appears to be the best explanation of the 3-dot syntax: 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.
Another way to read this: git diff develop...hotfix or git diff merge-destination...branch-to-merge
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
30.6k13 gold badges119 silver badges155 bronze badges
answered Sep 9, 2020 at 18:19

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.