有没有办法收集存储库中的分支列表以及最后提交日期?
换句话说,我想将这样的内容打印到标准输出:
branch_name_1 date1
branch_name_2 date2
branch_name_3 date3
这可能吗?
编辑:我尝试使用以下步骤:
git log --pretty=format:"%ad:%an:%d:%B"--date=short --branches
git branch -a
git ls-remote –heads
它们中的每一个都为我提供了我当前所在的存储库的分支。 但是现在我想检查是否可以从每个目录(到特定的 repo )运行命令。也以特殊格式打印。仍在尝试了解如何获取上次提交的日期。
Another-Edit:我考虑了一下,最好使用 git ls-remote –heads
因为我想检查一个非本地 repo。我如何检查 git ls-remote –heads
输出中每个分支的日期?
最佳答案
如果你的 Git 版本 >= 2.13,你可以使用相同的 git branch
命令执行此操作。
它有一个 --format
参数,您可以根据需要使用它来格式化输出。只需像这样运行它即可获得所需的输出。
git branch --format='%(refname:short)%09%(committerdate)' --sort=-committerdate
您可以添加一些颜色以使其清晰。
git branch --format='%(color:bold green) %(refname:short) %(color:white) %(committerdate)' --sort=-committerdate
输出:
Development Fri Jun 29 10:32:43 2018 +0530
feat-2180 Fri Jun 8 18:01:36 2018 +0530
master Wed May 16 17:19:21 2018 +0530
这是它支持的字段名称列表 - https://github.com/git/git/blob/v2.17.0/ref-filter.c#L328
============================================= ======================
编辑:
正如您在评论中提到的;我认为您无法使用 ls-remote
获取提交详细信息单独指挥。刚刚在这里查看了命令的源代码,它似乎没有返回任何其他值,除了 refs 和提交哈希值。所以我认为不可能使用它(如果我错了请纠正我)。
https://github.com/git/git/blob/maint/builtin/ls-remote.c
如果您可以进行临时克隆,我建议您创建一个 shell 脚本或某种脚本来进行克隆并获取摘要。
这是一个例子:
#!/usr/bin/env bash
REMOTE_URL=$1
git clone -q --depth 1 --bare --no-single-branch $REMOTE_URL /tmp/temp-git-clone
cd /tmp/temp-git-clone
git branch --format='%(color:bold green) %(refname:short) %(color:white) %(committerdate)' --sort=-committerdate
rm -rf /tmp/temp-git-clone
我在 clone
中使用了以下参数命令使它更快一点。
--depth 1
= will get only the last commit
--bare
= create a bare repository, which means there will be no working directory and it won't copy the files.
--no-single-branch
= need this to tell the clone command to get all branches
如果您运行脚本:./summary.sh <your repo url>
它会按照您的预期显示摘要!
希望对您有所帮助:)
关于git - 以特殊格式收集存储库中所有分支的列表 [Git],我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51362007/