Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

How to find all the commits made on a branch?

Benjamin Fernandez September 26, 2016

Hi, I have a GIT project with more than 2000 branches and more than 2000 commits.

There are a branch called "1595", I don't know who made it, when was merged, or wich files are affected, so, I am looking for any way to "search" all the commits made on this branch, and then find all the files affected by their commits.

There are any way to do it using Sourcetree or Bitbucket?

6 answers

1 accepted

6 votes
Answer accepted
Seth
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2016

Git doesn't track information like that. A branch is just a named reference to a commit, and if you commit to a branch, it moves that reference.

What you can do is see all of the commits that are ancestors of that branch, but many of those will have been committed to other branches that either pre-dated your "1595", or were merged into it.

To do that in SourceTree, checkout that branch. In the log view, use the dropdown at the top to view "current branch". If you merge frequently, you may be able to use merge commit descriptions to get a rough idea of what branch sections of older commits belong to.

There may be a better way to do this using a git command line, but this isn't the best forum for those questions.

Benjamin Fernandez September 26, 2016

Thank you for your help, I always imagined a branch like a "group" of commits, now I understand it better, selecting "current branch" on the dropdown was a great way to find what I need.

Like # people like this
thinsoldier
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 26, 2016

I vaguely remember a blog post about a post-commit script that would automatically add a git-note containing the name of the current branch whenever the author made a commit. Something like that might be useful to you in the future.

Like Werner Horbelt likes this
Mohammed Asif, Nabil October 16, 2023

@Benjamin Fernandez You can! Using the tag:

 

?until=refs/heads/<branch-name>

My example:

 

curl -u <user>:<pass> -X GET "https://stash.xxx.com/rest/api/latest/projects/<project-key>/repos/<repo-slug>/commits?until=refs/heads/feature/ALMENGI-460"
8 votes
nmaqsudov February 2, 2018

I'm not quite sure if this would be absolutely robust for anybody, I use the following way:

  1. Checkout to the branch that has at least one commit
  2. git rev-list --simplify-by-decoration -2 HEAD
    this gives me just two SHAs: 1) last commit of the branch [C1] 2) and commit parent to the first commit of the branch [C2]
  3. git log --decorate --pretty=oneline --reverse --name-status <C2>..<C1>
    Now I get a list of full history of file changing within the branch

Connor Lee June 27, 2018

Hello Naeel,

Would you mind explaining your step 2 here? I'm using your answer to write a ruby script that will list all files changed on a branch that has not yet been merged into the development branch, the relevant snippit looks like this:

commit_range = `(git rev-list --simplify-by-decoration -2 HEAD)`
.split(/\n+/)
committed_files = `git log --pretty=format:'' --name-only #{commit_range[1]}..#{commit_range[0]}`
.split(/\n+/)
.uniq

I'm just having trouble understanding what's going on? If I exclude --simplify-by-decoration, I get the same hashes, but I'm not sure if that's necessarily always going to to be the case. It works as expected but I'm asking to see if there are any edge cases I should be aware of?

1 vote
Hennie El Amam March 8, 2018

Another option is via stash/bitbucket. 

 

1- create a pull request for the branch

2- select source and destination features

3-  at the bottom of the screen you have a nice overview of all the commits/diff. Here you can see the commits and messages, but also al the edited code in the "diff" tab. 

1 vote
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 27, 2016

Not quite sure if the folowing can give you the searched info - it has even to be done on command line ... wink

Benjamin Fernandez September 28, 2016

That's awesome, I don't like use command line, It would be useful if sourceTree show us more options like this.

Like rchylla likes this
Johannes Kilian
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 28, 2016

git has way to many commands and options to be exposed in a  GUI in a meaningful and clear way.

Those things are mostly for expert level and not for the "normal" user - for whom the most git-GUIS are designed for

0 votes
Mohammed Asif, Nabil October 16, 2023

@Benjamin Fernandez You can! Using the tag:

?until=refs/heads/<branch-name>

My example:

curl -u <user>:<pass> -X GET "https://stash.xxx.com/rest/api/latest/projects/<project-key>/repos/<repo-slug>/commits?until=refs/heads/feature/ALMENGI-460"
0 votes
Ajay Kumar August 6, 2018

Thanks

Raghu Ram Bodapati February 16, 2021

In the bit bucket you have an option called " Commits " there you can just check for the commit you are looking for. But make sure you select the branch you are looking for.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events