该脚本似乎已经列出了 git 对象 ID。
如果您有兴趣清理特定的提交,可以使用command line "Which commit has this blob?" 检查特定对象 ID 是否是所述提交的一部分。
git log --all --pretty=format:%H -- <path> | \
xargs -n1 -I% sh -c "git ls-tree % <path> | \
grep -q <hash> && echo %"
例如,在我的repo seec:
a255b5c1d469591037e4eacd0d7f4599febf2574 12884 seec.go
a7320d8c0c3c38d1a40c63a873765e31504947ff 12928 seec.go
我要清理a7320d8版本的seec.go;
如在 BFG commit 12d1b00 中看到的:
人们可以使用以下方式获取 blob-id 列表
“git rev-list --all --objects”,然后 grep 列出他们想要核对的目录中的所有文件,并将其传递给 BFG。
注意:bi test 读作:
val blobIdsFile = Path.createTempFile()
blobIdsFile.writeStrings(badBlobs.map(_.name()),"\n")
run(s"--strip-blobs-with-ids ${blobIdsFile.path}")
表示-bi 的参数是一个文件,其中包含blob id。
我还可以通过查找提交来检查我刚刚得到的确实是 blob id:
vonc@bvonc MINGW64 ~/data/git/seec (master)
$ git log --all --pretty=format:%H -- seec.go | xargs -n1 -I% sh -c "git ls-tree % seec.go|\
grep -q a7320d8 && echo %"
我得到:commit c084402。
让我们看看该提交是否确实包含 seec.go 修订 blob id a7320d8(使用“Git - finding the SHA1 of an individual file in the index”)。
我可以从 GitHub 提交中找到文件的 blob id:
vonc@bvonc MINGW64 ~/data/git/seec (master)
$ (echo -ne "blob $(curl -s https://raw.githubusercontent.com/VonC/seec/c084402/seec.go --stderr -|wc -c)\0"; \
curl -s https://raw.githubusercontent.com/VonC/seec/c084402/seec.go --stderr -) | \
sha1sum | awk '{ print $1 }'
a7320d8c0c3c38d1a40c63a873765e31504947ff
宾果游戏。
如果我想去掉 seec.go blob id a7320d8,我知道我可以将该 blob id 传递给 bfg(在“blob ids”文件中)。