简体   繁体   English

以漂亮的格式将提交 hash 传递给 git function

[英]Pass commit hash to a git function in a pretty format

My git repo is huge (and created by people knowing only clearcase) and I want to find all the commits refering to an issue Id on all branches and at the same time knowing which branches contain the commits.我的 git 存储库很大(并且由只知道 clearcase 的人创建),我想找到所有分支上引用问题 ID 的所有提交,同时知道哪些分支包含提交。

However, the following attempt won't work as the $(git branch …) is expanded before the %h is.但是,以下尝试将不起作用,因为$(git branch …)%h之前展开。

git log --all --oneline --grep="FOO-1337" --pretty=format:"%C(auto)%h $(git branch --contains=%h)"

Is there a shorter solution than looping through the output of git log as in the following:是否有比循环通过git log的 output 更短的解决方案,如下所示:

for commit in $(git log --all --oneline --grep="FOO-1337" --pretty=format:"%h");
do
     branches=$(git branch --contains=$commit | tr '\n' ',')
     git show --oneline --quiet --pretty=format:"%C(auto)%h ${branches}" $commit; 
done

(which I can, of course define as an alias but it seems a bit contrived to me) (我当然可以将其定义为别名,但对我来说似乎有点做作)

How about including the decorate info in the format:如何在格式中包含装饰信息:

git log --all --oneline --grep="FOO-1337" --pretty=format:"%C(auto)%h %D"

won't that do the trick?这不是诀窍吗?

If I understand well, you would like your git log command to show all branch names?如果我理解得很好,您希望您的git log命令显示所有分支名称吗? You could just use the --decorate option which will show all references (branches, tags, ...) for each commit: something like:您可以只使用--decorate选项,该选项将显示每个提交的所有引用(分支、标签等):类似于:

git log --all --oneline --decorate ...

If you only want the branches to be shown (and not the tags), you could use:如果您只想显示分支(而不是标签),您可以使用:

--decorate-refs=refs/{remotes,heads}/

more information in the git log documentation git 日志文档中的更多信息

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM