Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

List all commits in a topic branch

Tags:

git

I have a feature branch concisely named feature that has about 100 commits all related to a feature of sorts. These commits were all merged into the master branch over the time. I want to list all commits that were on the branch so I can re-add the feature to other project.

Basically I want to have commit IDs for the green dots on the graph below.

relevant commits

How can I do that in Git other then by going to gitk or similar tool and hand-collecting all the relevant commit IDs?

like image 724
sanmai Avatar asked Jul 22 '13 03:07

sanmai


People also ask

How do you get list of all commits in a branch?

Locally, you can use git log . The git log command enables you to display a list of all of the commits on your current branch. By default, the git log command presents a lot of information all at once.

How do I see all commits on a repository?

On GitHub, you can see the commit history of a repository by: Navigating directly to the commits page of a repository. Clicking on a file, then clicking History, to get to the commit history for a specific file.

How do you find all commits to a file in git?

2.1 git log to display all the commit_id, the first one is the last commit_id, copy it. 2.2 git show commit_id --name-only to display all the files committed in the specified commit_id.

How do I list all commits before rebase?

Git rebase interactive in the console To use git rebase in the console with a list of commits you can choose, edit or drop in the rebase: Enter git rebase -i HEAD~5 with the last number being any number of commits from the most recent backwards you want to review. In vim, press esc , then i to start editing the test.


2 Answers

If you get the starting point of the specific branch, e.g., SHA1, try this:

git log --pretty=oneline SHA1^..feature
like image 171
yuwang Avatar answered Sep 18 '22 16:09

yuwang


Despite answer is given and accepted I would suggest more automatic way for doing this (but it will only work if you did not merge your master to feature):

Considering the following history:

--A---B---C---D---E---F---G (master)
       \     /       /
        H---J-------K       (feature)

Basically we want to perform git log B..feature.

git log --format='%H' feature..master | tail -1 | \
xargs -I '{}' git log '{}'^..feature

git log --format='%H' feature..master | tail -1 will find the commit to the master that was done right after you created feature branch - this is C

And ancestor of C - B will also be the ancestor of the first commit H of feature branch.

Then xargs -I '{}' git log '{}'^..feature (that is turns to git log B..feature) just shows the commits that is reachable from feature but don't reachable from the B.

like image 33
Max Komarychev Avatar answered Sep 21 '22 16:09

Max Komarychev