Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Git log to get commits only for a specific branch

Tags:

git

I want to list all commits that are only part of a specific branch.

With the following, it lists all the commits from the branch, but also from the parent (master)

git log mybranch 

The other option I found, was to exclude the commits reachable by master and gives me what I want, BUT I would like to avoid the need of knowing the other branches names.

git log mybranch --not master 

I was trying to use git for-each-ref, but it is also listing mybranch so actually it is excluding all:

git log mybranch --not $(git for-each-ref --format '^%(refname:short)' refs/heads/) 

Update:

I'm testing a new option that I found a while ago, and till now seems that this could be what I was looking for:

git log --walk-reflogs mybranch 

Update (2013-02-13T15:08):

The --walk-reflogs option is good, but I checked that there is an expiration for reflogs (default 90 days, gc.reflogExpire).

I think I found the answer I was looking for:

git log mybranch --not $(git for-each-ref --format='%(refname)' refs/heads/ | grep -v "refs/heads/mybranch") 

I'm just removing the current branch from list of branches available and using that list to be excluded from the log. This way I only get the commits that are only reached by mybranch.

like image 730
dimirc Avatar asked Feb 13 '13 07:02

dimirc


People also ask

How can I see commits from one branch?

Git rev-list will list commits in one branch that are not in another branch. It is a great tool when you're trying to figure out if code has been merged into a branch or not. Using the --oneline option will display the title of each commit.

How do I commit history to only one branch?

I think an option for your purposes is git log --oneline --decorate . This lets you know the checked commit, and the top commits for each branch that you have in your story line. By doing this, you have a nice view on the structure of your repo and the commits associated to a specific branch.

Does git log show all branches?

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.


1 Answers

From what it sounds like you should be using cherry:

git cherry -v develop mybranch 

This would show all of the commits which are contained within mybranch, but NOT in develop. If you leave off the last option (mybranch), it will compare the current branch instead.

As VonC pointed out, you are ALWAYS comparing your branch to another branch, so know your branches and then choose which one to compare to.

like image 188
Smilie Avatar answered Oct 22 '22 21:10

Smilie