[英]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. 我有一个功能分支简明命名的
feature
,有大约100个提交都与各种功能相关。 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. 基本上我想在下图中为绿点提供ID。
How can I do that in Git other then by going to gitk or similar tool and hand-collecting all the relevant commit IDs? 我怎么能在Git中做到这一点,然后转到gitk或类似的工具并手工收集所有相关的提交ID?
如果你得到特定分支的起点,例如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
): 尽管给出并接受了答案,我建议采用更自动的方法(但只有在你没有将你的
master
与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 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
git log --format='%H' feature..master | tail -1
将在您创建feature
分支后立即找到对master
的提交 - 这是C
And ancestor of C
- B
will also be the ancestor of the first commit H
of feature
branch. C
- B
的祖先也将是feature
分支的第一个提交H
的祖先。
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
. 然后
xargs -I '{}' git log '{}'^..feature
(转到git log B..feature
)只显示可以从feature
访问但无法从B
访问的提交。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.