列出主题分支中的所有提交 [英] List all commits in a topic branch

查看:70
本文介绍了列出主题分支中的所有提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简明命名为feature的功能分支,其中约有100个提交都与某种功能相关.这些提交都在一段时间内全部合并到master分支中.我想列出分支上的所有提交,以便可以将功能重新添加到其他项目中.

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.

基本上,我想在下图上显示绿色圆点的提交ID.

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

除了转到gitk或类似工具并手工收集所有相关的提交ID之外,我还可以如何在Git中做到这一点?

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

推荐答案

尽管给出并接受了我的建议,但我还是建议采用更自动的方式(但这仅在您未将master合并到):

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):

考虑以下历史记录:

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

基本上我们要执行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将找到创建feature分支后即完成的对master的提交-这是C

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

C-B的祖先也将是feature分支的第一次提交H的祖先.

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

然后xargs -I '{}' git log '{}'^..feature(即变为git log B..feature)仅显示可以从feature访问但不能从B访问的提交.

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.

这篇关于列出主题分支中的所有提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆