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:
This answer: What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
Another answer: What are the differences between double-dot ".." and triple-dot "..." in Git diff commit ranges?
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]
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:
git log --no-merges branch1 ^master
show all NON-merge commits in branch1 which are NOT in master!
git log --oneline --no-merges branch1 ^branch2 ^branch3
same as above, but show only one line per commit! <======= EXCELLENT! (& SIMPLEST) ========
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!