Windows上的git blame报告“致命:没有这样的路径< path>在HEAD中" [英] git blame on windows reports "fatal: no such path <path> in HEAD"
问题描述
当我在文件夹(例如)中的文件上运行git blame时:
When I run git blame on a file in a folder e,g,:
git blame Foo/FileA.txt
它返回
fatal: no such path 'Foo/FileA.txt' in HEAD
我可以清楚地看到该文件存在于文件系统上,并且可以成功归咎于同一文件夹中的其他文件-那么怎么回事?
I can clearly see that this file exists on the file system, and other files in the same folder can be successfully blamed - so what is going on?
我要发布这个问题和答案,因为今天它让我很困惑.我找不到一个能解决所有问题的答案.
I'm posting this question and answer as it had me stumped for a while today, and I couldn't find a single answer that hit all of the solution.
推荐答案
这是由于使用新名称重命名了文件系统上的父文件夹,该新名称仅因大小写而异-并且某些文件是在提交之前添加的,重命名文件夹.这是Powershell提示下的复制:
This is due to renaming a parent folder on the file system with a new name that varies only by case - and some files were added in a commit occurring before the rename of the folder. Here is a repro, from a Powershell prompt:
mkdir C:\RenameProblem
cd C:\RenameProblem
git init
mkdir foo
"FileA" > foo/FileA.txt
git add foo/FileA.txt
git commit -m "Add FileA"
然后在Windows资源管理器中,将目录"foo"重命名为"Foo",然后在Powershell中继续执行以下操作:
Then in windows explorer, rename directory "foo" to "Foo" and then continue in Powershell with:
"FileB" > Foo/FileB.txt
git add Foo/FileB.txt
git commit -m "Add FileB"
此时,git blame /Foo/FileA.txt
(由于文件夹已重命名,将生成选项卡补全)将失败,并且没有此类路径错误,而git blame /Foo/FileB.txt
甚至git blame /foo/FileA.txt
将成功.
At this point, git blame /Foo/FileA.txt
(which tab completion will generate since the folder has renamed) will fail with the no such path error, whereas git blame /Foo/FileB.txt
or even git blame /foo/FileA.txt
will succeed.
更进一步,对git ls-files Foo
的调用将仅列出FileB.txt
,而git ls-files foo
的调用仅列出FileA.txt
.在Windows上不是一个好地方.
Futhermore, a call to git ls-files Foo
will list only FileB.txt
and git ls-files foo
will list only FileA.txt
. Not a great place to be on Windows.
就我而言,我在文件夹名称的两个版本之间分配了大量文件.
In my case, I had a large number of files split between the two versions of the folder name.
您可以通过使用git mv
重命名文件来解决此问题:
You can solve this by renaming the file with git mv
:
git mv foo/FileA.txt Foo/FileA.txt
git commit -am "Rename foo to Foo"
如果您需要重命名很多文件,请使用一些Powershell(也请注意,git mv
具有-n
开关可进行假设分析"试运行,因此可以检查重命名为正确):
If you need to rename a lot of files, use a bit of Powershell (also, note that git mv
has a -n
switch to do a "what-if" dry run, so you can check your rename is correct):
git ls-files foo | % { (& git mv $_ $('F' + $_.Substring(1))) }
以上使用git ls-files
获取问题"foo"文件夹中的文件列表,并将其通过管道传输到"ForEach"(%
是该快捷方式),然后为每个提供文件执行git mv
原始名称($_
)和新名称'F'以及文件名的其余部分('F' + $_.Substring(1))
)
The above uses git ls-files
to get a list of files in the problem "foo" folder, pipes this into a "ForEach" (%
is the shortcut for that) and then executes git mv
for each file supplying the original name ($_
) and the new name of 'F' and the rest of the file name ('F' + $_.Substring(1))
)
这篇关于Windows上的git blame报告“致命:没有这样的路径< path>在HEAD中"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!