简体   繁体   中英

List all commits in a topic branch

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.

相关承诺

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

如果你得到特定分支的起点,例如SHA1 ,试试这个:

git log --pretty=oneline SHA1^..feature

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 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 .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM