Given a branch, I'd like to see a list of commits that exist only on that branch. In this question we discuss ways to see which commits are on one branch but not one or more specified other branches.
This is slightly different. I'd like to see which commits are on one branch but not on any other branches.
The use case is in a branching strategy where some branches should only be merged to, and never committed directly on. This would be used to check if any commits have been made directly on a "merge-only" branch.
EDIT: Below are steps to set up a dummy git repo to test:
git init echo foo1 >> foo.txt git add foo.txt git commit -am "initial valid commit" git checkout -b merge-only echo bar >> bar.txt git add bar.txt git commit -am "bad commit directly on merge-only" git checkout master echo foo2 >> foo.txt git commit -am "2nd valid commit on master" git checkout merge-only git merge master
Only the commit with message "bad commit directly on merge-only", which was made directly on the merge-only branch, should show up.
The git log command displays all of the commits in a repository's history.
`git log` command is used to view the commit history and display the necessary information of the git repository. This command displays the latest git commits information in chronological order, and the last commit will be displayed first.
In order to see the commit differences between two branches, use the “git log” command and specify the branches that you want to compare. Note that this command won't show you the actual file differences between the two branches but only the commits.
We just found this elegant solution
git log --first-parent --no-merges
In your example of course the initial commit still shows up.
this answer does not exactly answer the question, because the initial commit still shows up. On the other hand many people coming here seem to find the answer they are looking for.
Courtesy of my dear friend Redmumba:
git log --no-merges origin/merge-only \ --not $(git for-each-ref --format="%(refname)" refs/remotes/origin | grep -Fv refs/remotes/origin/merge-only)
...where origin/merge-only
is your remote merge-only branch name. If working on a local-only git repo, substitute refs/remotes/origin
with refs/heads
, and substitute remote branch name origin/merge-only
with local branch name merge-only
, i.e.:
git log --no-merges merge-only \ --not $(git for-each-ref --format="%(refname)" refs/heads | grep -Fv refs/heads/merge-only)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With