![](/img/trans.png)
[英]'Git GC' command deleted all files in 'objects' folder, yet I can access the objects from Git bash
[英]How can I tweak this git log command / bash script to include deleted commits from deleted branches that git reflog should still know about?
所以我有这个小脚本 bash 到 output 一个 csv 文件,它显示了我从特定月份开始的所有提交历史记录。
function make-git-report() {
if [ "$1" != "" ]
then
local month=$1
else
local month=$(date +%m)
fi
local year=$(date +%Y)
local nextYear=$year
local nextMonth=$((month+1))
if [ "$nextMonth" = "13" ]
then
local nextMonth="01"
local nextYear=$((year+1))
fi
local start="$year-$month-01"
local end="$nextYear-$nextMonth-01"
rm -f log.csv
git --no-pager log \
--author="Evert" \
--since="$start" \
--before="$end" \
--branches --remotes --tags --no-decorate --no-merges \
--pretty=format:'§"%ch";"%an";"%s";' --stat | \
grep -v \| | tr -s "\n\n" | tr "\n" '"' | tr "§" "\n" > templog.csv
echo "\nDate;Author;Message;Changes" >> templog.csv
tac templog.csv > log.csv
rm -f templog.csv
}
但我刚刚意识到,如果一个分支在那个月被删除,并且它只是使用压缩合并进行合并,那么很多提交将不会出现在我的 csv 文件中。
我知道git reflog
仍会以某种方式包含丢失的数据,但我不确定如何将该信息从git log
合并到 output 中,同时优雅地避免诸如重复条目之类的事情以及我现在无法获得的更多不需要的结果考虑到。
任何人都可以给我一点提示,朝着正确的方向推动如何解决这个问题吗?
您不能使用 reflog 可靠地获取有关已删除分支的信息:
仅当您完全看到提交时,日志才会更新
例如:如果你请假 2 天,你的本地仓库将不会记录这两天发生的事情......
同一个 repo 的两个克隆不会有相同的 reflog
reflog 还将包含有关 rebased/cherry-picked 提交的信息(并可能在您尝试构建的日志中添加重复信息?)
HEAD 的 reflog 将保留,但如果所述分支也被删除,则特定分支/远程分支的 reflog 将被删除
ETC...
我猜你描述了一个基于已知 git 中央服务(github?gitlab?azure devops?......)的工作流程,你的分支通过拉取请求合并。
这些服务中的每一个都保留指向其拉取请求分支的链接:
git ls-remote
,然后查看列出了哪些引用(您应该看到refs/pull/xxx/...
或refs/merge-requests/xxx/...
的列表或。 ..)您可以获取这些拉取请求:
# with this refspec : all pull requests will be stored under origin/pull/*,
# as if they were remote branches
git fetch origin +refs/pull/*:refs/remotes/origin/pull/*
# or you may choose to store them in a different set of refs :
git fetch origin +refs/pull/*:refs/pull/*
您也可以使用上述服务的 API 来查看 pull request 的 state。
结合以上信息,您可以选择,逐个请求请求,是否应将pull/xyz/head
添加到git log
命令中的引用列表中。
请注意,如果您的分支是挤压合并的,则“合并提交”实际上不会是合并提交,因此您必须选择除--no-merges
之外的另一种方式将它们从您的日志中排除(例如:打印提交 sha并跳过那些已知是合并请求结果的)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.