有没有办法用git log显示远程引用?

时间:2017-07-06 09:52:07

标签: git gerrit git-log

git log --oneline

上面的命令给出了以下结果:

5485b34 Modify: something 
ccaf2c4 Modify: another thing
85a87e8 Bug Fix: the other thing

但是因为我使用的是gerrit而且通常认为gerrit将它的更改号码改为refs / changes / ...格式,我想收集列表框如下:

refs/changes/85/104085/9 Modify: something
refs/changes/33/104033/9 Modify: another thing
refs/changes/83/104183/2 Bug Fix: the other thing

我知道有一种方法可以使用" git ls-remote"来获取提交ID和远程引用之间的映射。通过使用" git ls-remote",我可以制作一个脚本来获得上述结果。但有没有更好,更简单的方法来获得上述结果?

3 个答案:

答案 0 :(得分:1)

您可以使用--decorate选项在日志中显示引用 但它只会显示本地和提取的引用,因此refs/changes/x/yyyy/zz不会显示,您必须先获取它们:

git config --add remote.origin.fetch refs/changes/*:refs/remotes/gerrit/changes/*

然后你会得到这样的输出:

# You can add '--all' to see other references not in the current history
$ git log --oneline --decorate
5485b34 (HEAD -> master, origin/master, origin/HEAD, gerrit/changes/85/104085/9) Modify: something 
ccaf2c4 (gerrit/changes/33/104033/9) Modify: another thing
85a87e8 (gerrit/changes/83/104183/2) Bug Fix: the other thing

答案 1 :(得分:0)

我认为不可能以您想要的方式获取信息,但您可以获得大量Gerrit评论信息,执行以下操作:

1)配置您的存储库以获取评论信息

$ git config --add remote.origin.fetch refs/notes/review:refs/notes/review

2)之后,每次更新都会带来评论信息

$ git fetch

remote: Counting objects: 66, done
remote: Finding sources: 100% (66/66)
remote: Total 66 (delta 18), reused 66 (delta 18)
Unpacking objects: 100% (66/66), done.
From https://GERRIT-SERVER/REPO-FULLNAME
* [new ref] refs/notes/review -> refs/notes/review

3)要查看评论信息,请添加" - notes = review"到你的" git log"命令

$ git log --notes=review

commit a5bc87cb44e5e68154fb8bd3559f9753e1540fd7
Author: AUTHOR
Date: Thu May 8 16:02:16 2017 -0300
COMMIT-MESSAGE
Change-Id: CHANGE-ID
Notes (review):
Verification+1: REVIEWER1
Code-Review+1: REVIEWER2
Code-Review+1: REVIEWER3
Code-Review+2: REVIEWER4
Submitted-by: SUBMITTER
Submitted-at: Fri, 09 May 2017 08:23:28 -0300
Reviewed-on: https://GERRIT-SERVER/CHANGE-NUMBER
Project: REPO-FULLNAME
Branch: refs/heads/BRANCH

答案 2 :(得分:-1)

您可以使用git log --oneline --pretty=format:'you_format_here'

获得所需内容

查看所有可用选项的手册页:https://git-scm.com/docs/pretty-formats