If I do git log
, is there any parameter I could specify to be able to tell from the output which branch every commit belongs to?
Edit: to clarify, I understand that a commit may be part of two branches (for instance). What I want is to get the most recent branch that the commit in log
belongs to. So, if I made a branch called foo
from master
. It would belong to both branches, but I want to get foo
.
It is based on "Find merge commit which include a specific commit". Find when a commit was merged into one or more branches. Find the merge commit that brought COMMIT into the specified BRANCH(es). Specifically, look for the oldest commit on the first-parent history of BRANCH that contains the COMMIT as an ancestor.
As you start making commits, you're given a master branch that points to the last commit you made. Every time you commit, the master branch pointer moves forward automatically. The “master” branch in Git is not a special branch. It is exactly like any other branch.
Graph all git branchesDevelopers can see all branches in the graph with the –all switch. Also, in most situations, the –decorate switch will provide all the supplemental information in a formatted and nicely color-coded way.
I think that what you're looking for is the very useful command:
git branch -a --contains <SHA1sum-of-commit>
... which will tell you every branch (both local and remote-tracking) that contains that commit.
Unfortunately, I don't think there's a git log
option that just outputs this for every commit. Using --all --source
is close, but will only display one of the branches for each commit. However, if you click on a commit in gitk --all
, you'll see that it lists every branch that that commit is on.
There's one part of your question that isn't very well defined, however - you ask:
What I want is to get the most recent branch that the commit in log belongs to
It isn't clear to me what you mean by this - the "most recent branch" might be (a) the most recently created ref (b) the most recently modified ref (c) the branch with the most recent commit on it, etc. etc. There's probably a better way of defining what you want in terms of the commit graph.
With git log
you already get all the commits from the current branch you are on.
If you want to see commits from merged branches you can use
$ git log --pretty=oneline --graph
To create a log tree and see what merged branches a commit stems from.
--graph
will make the commit tree and
--pretty=oneline
will make a one line visualization for every commit
To add branches (as refs) to the log:
$ git log --all --source --pretty=oneline --graph
To display branches with commits:
$ git show-branch
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