如何在裸的 Git 存储库上使用 `git blame --ignore-revs-file` 命令

5

命令git blame --ignore-revs-file .git-blame-ignore-revs add.txt在我的本地非裸库上运行正常,但当我获取同一本地库的裸库并尝试相同的命令时,会发生以下情况:

git blame --ignore-revs-file .git-blame-ignore-revs add.txt
fatal: could not open object name list: .git-blame-ignore-revs

还注意到当我们在文件系统中的其他位置传递相同内容的复制文件时,它可以正常工作。 例如:git blame --ignore-revs-file /tmp/.git-blame-ignore-revs add.txt可以正常工作。

我认为这可能是因为它无法在裸仓库中找到所提到的路径,因此我尝试了以下操作:

git blame --ignore-revs-file -- .git-blame-ignore-revs add.txt

但结果是: fatal: bad revision '.git-blame-ignore-revs'

有人能帮我理解如何在运行针对裸仓库的git命令时将文件路径传递给选项吗?或者根本不可能?

3个回答

5
git blame --ignore-revs-file -- .git-blame-ignore-revs add.txt

but that resulted in : fatal: bad revision '.git-blame-ignore-revs'

I asked the question to understand if it is possible to used the checked in file in the repo.

是的,但git blame --ignore-revs-file的语法是:

git blame --ignore-revs-file <file>  -- <file>

意思:

  • <file>(在双破折号之前)是你的.git-blame-ignore-revs
  • <file>(在双破折号之后)是你要追溯责任的文件。

通过将.git-blame-ignore-revs放在--之后,您强制git命令将其视为“非选项参数”。


在一个裸仓库中,没有工作树,因此--ignore-revs-file没有实际文件可供参考。

3

编辑:啊,我明白了。你想要使用那个文件的提交版本。裸克隆中的仓库内容通常不存在于单独的文件中,历史记录是以包的形式发送的。你必须要请求git显示该提交文件的内容:

git blame --ignore-revs-file <(git show @:.git-blame-ignore-revs) add.txt

或者为了纯度点数,火炮防护未来性和几微秒的速度,

git blame --ignore-revs-file <(git cat-file blob @:.git-blame-ignore-revs) add.txt

当我这样做时,它可以工作:

sh -x <<\EOD; rm -rf deleteme
git init --bare deleteme; cd $_
git update-index --add --cacheinfo 100000,$(git hash-object -w config),add.txt
git --work-tree . commit -m-
git log --oneline --name-status
> .git-blame-ignore-revs
git blame --ignore-revs-file .git-blame-ignore-revs add.txt
EOD

当我这样做时

sh -x <<\EOD; rm -rf deleteme
git init --bare deleteme; cd $_
git update-ref HEAD $(git commit-tree -m - $(git mktree <&-))
> .git-blame-ignore-revs
git blame --ignore-revs-file .git-blame-ignore-revs add.txt
EOD

错误信息为fatal: no such path add.txt in HEAD

所以我认为你的第一个测试确实没有那个忽略列表。


好奇了解第二个选项“或者为了纯度点,火炮证明的未来证明和几微秒的速度”,如何能够节省几微秒。 - Harish Gajapathy
git show是"瓷器",由git log实现(基本上是git log --no-walk -p),它完成了全部设置,包括扫描所有调整的配置以及所有git diff - jthill

2

即使是在裸仓库中,相同的命令也适用于我。前提是文件.git-blame-ignore-revs必须存在于当前目录(裸仓库所在的目录)中。

请注意,即使文件.git-blame-ignore-revs已经检入到仓库中,该文件也必须存在于文件系统中,路径由--ignore-revs-file选项指定。

很可能您之前遇到错误只是因为当前目录中缺少文件.git-blame-ignore-revs


请注意,即使文件.git-blame-ignore-revs已经提交到仓库中,该文件也必须存在于文件系统中,路径应与--ignore-revs-file选项指定的路径相同。这已经是众所周知的了。正如我在问题中所述,当文件存在于文件系统的其他位置时,它可以工作。我提出这个问题是为了了解是否可能使用存储在仓库中的文件。 - Harish Gajapathy
1
不可能的,据我所知。 - Dheeraj Vepakomma

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接