gpt4 book ai didi

Git 归咎于尚未提交的重命名文件

转载 作者:太空狗 更新时间:2023-10-29 14:00:29 27 4
gpt4 key购买 nike

我有一个文件,我使用 git mv oldfilename newfilename 重命名了

在提交此更改之前,如何对这个文件执行 git blame?由于尚未提交,因此未采用重命名。

> git blame newfilename
> fatal: no such path 'newfilename' in HEAD

并且旧文件名不再存在。

> git blame oldfilename
> fatal: cannot stat path 'oldfilename': No such file or directory

最佳答案

鉴于您已将文件移动告知 git,您会认为它可以解决。但事实并非如此。

--contents开关将完成你想要的。来自git-blame手册页...

--contents <file>
When <rev> is not specified, the command annotates the changes starting
backwards from the working tree copy. This flag makes the command pretend as if
the working tree copy has the contents of the named file (specify - to make the
command read from the standard input).

git blame --contents newfilename -- oldfilename将在 oldfilename 出现在 HEAD 时进行 blame log,但使用 newfilename 的内容作为最新修订。

对于归咎于无论出于何种原因不再存在的文件的一般问题,请为 git blame 传递特定修订版. git blame <rev> -- <file> .所以git blame HEAD -- oldfilename将在上次提交时提供旧文件名的 blame 日志。

--通常用于告诉命令停止处理选项并将后面的内容视为普通参数。然而,git blame似乎重载了“不要查找文件”的正常含义......我认为。文档中并不完全清楚。

参见 "SPECIFYING RANGES" in the "git-blame" man page了解详情。

关于Git 归咎于尚未提交的重命名文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23250614/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com