git - 为什么 git blame --ignore-rev/--ignore-revs-file 对我不起作用?

标签 git ignore revision-history

git blame --ignore-revs-file显然是现代 Git 中存在的一个选项。
只有一个问题。它不起作用。
或者至少,它对我不起作用:
您可以将其添加到 shell 脚本中:

mkdir -p /tmp/blarp
cd /tmp/blarp
git init
cat << EOF > file.txt
one
two
three
EOF
git add file.txt
git commit --author "One <one@example.com>" -m 'one commit'
cat << EOF > file.txt
one
awesome
three
EOF
git add file.txt
git commit --author "Two <two@example.com>" -m 'two commits'
cat << EOF > file.txt
one
awesome
sauce
EOF
git add file.txt
git commit --author "One <one@example.com>" -m 'three commits'
git rev-parse HEAD~1 > ignore.txt
git blame --ignore-revs-file=ignore.txt file.txt
对我来说,这表明:
^b6d40d5 (One 2019-12-30 21:47:15 +0000 1) one
1c185c4c (Two 2019-12-30 21:47:15 +0000 2) awesome
d8b9bafd (One 2019-12-30 21:47:15 +0000 3) sauce
但我希望看到
^b6d40d5 (One 2019-12-30 21:47:15 +0000 1) one
^b6d40d5 (One 2019-12-30 21:47:15 +0000 2) two
d8b9bafd (One 2019-12-30 21:47:15 +0000 3) sauce
或者
^b6d40d5 (One 2019-12-30 21:47:15 +0000 1) one
d8b9bafd (One 2019-12-30 21:47:15 +0000 2) awesome
d8b9bafd (One 2019-12-30 21:47:15 +0000 3) sauce
但事实并非如此。我确实发现,如果更改只是空白更改,它们将被忽略……但 git 文档对此并不明确,只是建议:

--ignore-revs-file

Ignore revisions listed in file, which must be in the same format as an fsck.skipList. This option may be repeated, and these files will be processed after any files specified with the blame.ignoreRevsFile config option. An empty file name, "", will clear the list of revs from previously processed files.


任何线索为什么git blame --ignore-revs-file=revs-to-ignore似乎不适合我?

最佳答案

检查 Git 2.29(2020 年第 4 季度)是否修复了以下问题:“ git blame --ignore-rev/--ignore-revs-file ”( man )未能验证其输入是否为有效修订版,并且未能考虑到用户可能想要提供带注释的标签而不是提交,已更正。
commit 610e2b9 , commit f58931c (2020 年 9 月 24 日)来自 Junio C Hamano ( gitster ) .
(由 Junio C Hamano -- gitster -- merge 于 commit 230ff3e ,2020 年 10 月 4 日)

blame: validate and peel the object names on the ignore list


The command reads list of object names to place on the ignore list either from the command line or from a file, but they are not checked with their object type (those read from the file are not even checked for object existence).

Extend the oidset_parse_file() API and allow it to take a callback that can be used to die (e.g. when an inappropriate input is read) or modify the object name read (e.g. when a tag pointing at a commit is read, and the caller wants a commit object name), and use it in the code that handles ignore list.



在 Git 2.30(2021 年第一季度)中,“ git blame --ignore-revs-file=<file> (man)”学会了忽略输入中不存在的对象名称,而不是提示。
commit c714d05 (2020 年 11 月 10 日)来自 René Scharfe ( rscharfe ) .
(由 Junio C Hamano -- gitster -- merge 于 commit b4e245a ,2020 年 11 月 18 日)

blame: silently ignore invalid ignore file objects

Reported-by: Jean-Yves Avenard
Signed-off-by: René Scharfe
Reviewed-by: Barret Rhoden


Since 610e2b9240 ("blame: validate and peel the object names on the ignore list", 2020-09-24, Git v2.29.0-rc0 -- merge listed in batch #19) git blame(man) reports checks if objects specified with --ignore-rev and in files loaded with --ignore-revs-file and config option blame.ignoreRevsFile are actual objects and dies if they aren't. The intent is to report typos to the user.

This also breaks the ability to use a single ignore file for multiple repositories.
Typos are presumably less likely in files than on the command line, so alerting is less useful here.
Restore that feature by skipping non-commits without dying.

关于git - 为什么 git blame --ignore-rev/--ignore-revs-file 对我不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59537270/

相关文章:

Git diff -w 仅忽略行首和行尾的空格

mysql - 如何扩展此表以支持修订历史记录

git - 如何从快照创建具有自己历史记录的 git 存储库?

git - 使用 merge 或 rebase 来维护一个部署分支

git lfs prune 从 lfs 中删除文件并推送到源

Git 使用 HTTPS 访问私有(private)仓库

regex - git-svn clone 忽略文件夹的路径正则表达式

git - 设置git ssh访问报错: gitosis need more than 1 value to unpack

svn - "svn add *"甚至添加那些被忽略的文件

svn - 搜索文件及其所有 SVN 修订版