分支的Git日志占位符 [英] Git log placeholder for branch

查看:148
本文介绍了分支的Git日志占位符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有任何占位符用于显示git --pretty=format所在的分支名称(在git log和git show中)?

It there any placeholder for showing branch name that commit is in for git --pretty=format (in git log and git show)?

%H一样提交哈希吗?

推荐答案

提交不在分支中,分支只是挂在特定提交上的repo-local标签.例如,大多数项目只有一个根,并且每个分支都可以追溯到该根. Git不在乎哪个分支是您的主"分支,这完全是一个解释问题.

Commits aren't in branches, branches are just repo-local labels hung on a particular commit. For example, most projects have just one root and every single branch traces back to that. Git couldn't care less which if any branch is your "main" branch, that's entirely a matter of interpretation.

您可以

git branch --contains $thatcommit

查看所有可以追溯该提交祖先的分支,并且

to see all the branches that can trace ancestry for that commit, and

git log --branches --decorate --simplify-by-decoration --oneline \
        --ancestry-path --first-parent ^$thatcommit

查看所有通过祖先链接追溯到该提交的祖先分支(即不包括仅通过合并合并该提交的分支).

to see all the branches that trace ancestry to that commit via their first-parent links (i.e. not branches that incorporate that commit only by merge).

edit:说分支"确实很容易,但是对于新手来说,要牢记您在git中使用的每个名称都必须以很短的顺序追溯到对象db中原本没有区别的对象– refname只是回购中的方便之选.从理论上讲,更准确的说法是分支提示",甚至是分支提示提交".

edit: it's really easy to just say "branches", but for newcomers it's really hard to keep in mind that every name you use in git traces back in very short order to an otherwise-undifferentiated object in the object db -- a refname is just a handy thumb into the repo. More pedantically correct would be "branch tip" or even "branch tip commit".

关于分支ref的 only 特殊之处在于它的完整拼写是"refs/heads/$ branchname",当git checkout看到它时,它使HEAD成为对该符号的符号引用- -因此,每个更新head的人都会更新分支提示,而每个查看HEAD的人都会看到当前的分支提示.

The only thing special about a branch ref is its full spelling is "refs/heads/$branchname" and when git checkout sees it it makes HEAD be a symbolic reference to that -- so everybody that updates head instead updates the branch tip, and everybody that looks at HEAD sees the current branch tip.

您可以在分支引用上挂回购本地注释,在 branch.$branchname配置部分为其默认设置.

You can hang repo-local notes on branch refs, several convenience commands look in the branch.$branchname config section for their defaults.

这篇关于分支的Git日志占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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