我想列出只是特定分支的一部分的所有提交。
使用下面的代码,它列出了来自分支的所有提交,也包括来自父(master)的所有提交
git log mybranch
我发现的另一种选择是排除主可达的提交,并给我我想要的,但我想避免知道其他分支名称的需要。
git log mybranch --not master
我试图使用git for-each-ref,但它也列出了mybranch,所以实际上它排除了所有:
git log mybranch --not $(git for-each-ref --format '^%(refname:short)' refs/heads/)
更新:
我正在测试一个我不久前发现的新选项,直到现在看来,这可能是我一直在寻找的:
git log --walk-reflogs mybranch
更新(2013 - 02 - 13 t15:08):
——walk-reflogs选项很好,但我检查了reflogs的过期时间(默认90天,gc.reflogExpire)。
我想我找到了我一直在寻找的答案
git log mybranch --not $(git for-each-ref --format='%(refname)' refs/heads/ | grep -v "refs/heads/mybranch")
我只是从可用的分支列表中删除当前分支,并使用该列表从日志中排除。这样我只能得到只有mybranch才能到达的提交。
快速回答:
git log $(git merge-base master b2)..HEAD
比方说:
That you have a master branch
Do a few commits
You created a branch named b2
Do git log -n1; the commit Id is the merge base between b2 and master
Do a few commits in b2
git log will show your log history of b2 and master
Use commit range, if you aren't familiar with the concept, I invite you to google it or stack overflow-it,
For your actual context, you can do for example
git log commitID_FOO..comitID_BAR
The ".." is the range operator for the log command.
That mean, in a simple form, give me all logs more recent than commitID_FOO...
Look at point #4, the merge base
So: git log COMMITID_mergeBASE..HEAD will show you the difference
Git can retrieve the merge base for you like this
git merge-base b2 master
Finally you can do:
git log $(git merge-base master b2)..HEAD