如何查看一个git分支只返回到分支点? [英] How to view a git branch ONLY back to the point where it was branched off?
问题描述
我注意到当我在一个分支上时(我们称它为 feat-123
),这只是一对提交, git log
显示我从( develop
)分支的分支的整个历史记录。有没有什么方法可以在创建 feat-123
的地方显示日志?
没有简短的find 任何点历史重新加入,所以你必须使用像 Cupcake 和 D4NI3LS 建议:明确停止在或之前的日志记录这样一个点。
然而,有一种方法可以自动执行此操作。它可以封装在一个一行shell脚本中:
git log HEAD --not $(
git for-each-ref --format ='%(refname:short)'refs / heads / |
grep -v^ $(git symbolic-ref -q --short HEAD)$
)$ @
这是如何工作的:
- 最里面的位
git symbolic-ref -q --short HEAD
打印当前分支名称,或者根本不显示不在分支上(分离的HEAD状态)。
- 我们通过添加
^
开始行)和$
(在结尾定位)。 - 我们使用它来删除
git for-each-ref
输出中的当前分支(如果有的话)。
-
for-each -ref
output是每个分支的简短引用名称,即refs / heads /
中的每个引用。因此,例如,如果你的全套分支名称是monty
,python
,飞行
和circus
,并且您位于分支flying
上,它列出了monty
,python
和circus
。 - 最后,在询问
git log
开始于,而不是 code> HEAD 。log
命令使用git rev-list
从任何地方开始,然后继续向前,直到这种情况下,- 而不是
列表)使其停止。当然,我们还添加了$ @
,以便包含任何其他命令行参数。 b $ b由于它是一个单行代码,因此它可以嵌入
〜/ .gitconfig
中,作为别名
:[别名]
ltf =!git log HEAD --not $(git for-each-ref \
--format ='%(refname:short)'refs / heads | \
grep -v^ $(git symbolic-ref -q --short HEAD)$)
现在
git ltf
,git ltf --oneline
等等,都可以做到。 (我不知道我是否喜欢名称ltf
,它代表log to fork,但这更像是加入日志。也许lbr
为日志分支?)I noticed when I'm on a branch (we'll call it
feat-123
) that's only a couple commits in,git log
shows the whole history of the branch I branched from (develop
). Is there some way to show the log only as far back as the point from whichfeat-123
was created?解决方案There's no shorthand for "find any point where history rejoins", so you have to use something like what Cupcake and D4NI3LS suggested: explicitly stop logging at-or-before such a point.
There is, however, a way to automate this. It can be encapsulated in a "one line" shell script:
git log HEAD --not $( git for-each-ref --format='%(refname:short)' refs/heads/ | grep -v "^$(git symbolic-ref -q --short HEAD)$" ) "$@"
How this works:
- The innermost bit,
git symbolic-ref -q --short HEAD
, prints the current branch name, or nothing at all if you are not on a branch ("detached HEAD" state). - We turn this into a grep pattern by adding
^
(anchor at start-of-line) and$
(anchor at end). - We use that to remove the current branch (if any) from
git for-each-ref
output. - The
for-each-ref
output is the short refname for every branch, i.e., every ref inrefs/heads/
. Thus, if your complete set of branch names are, for instance,monty
,python
,flying
, andcircus
and you're on branchflying
, this listsmonty
,python
, andcircus
. - Finally, we give all of this to
--not
, after askinggit log
to start atHEAD
. Thelog
command usesgit rev-list
to start from wherever you ask it, and keep going backwards until something (in this case, the--not
list) makes it stop. And of course we add"$@"
so that any other command-line arguments are included.
Since it's a one liner, it can be embedded in
~/.gitconfig
, as analias
:[alias] ltf = !git log HEAD --not $(git for-each-ref \ --format='%(refname:short)' refs/heads | \ grep -v "^$(git symbolic-ref -q --short HEAD)$")
and now
git ltf
,git ltf --oneline
, etc., all do the trick. (I don't know if I like the nameltf
, it stands for "log to fork" but this is more of a "log to join". Maybelbr
for "log branch"?)这篇关于如何查看一个git分支只返回到分支点?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
- The innermost bit,