无法使用 Git Blame 命令查看文件信息

3
我在两台不同的笔记本电脑上使用Xcode和这个仓库。在其中一台电脑上,我可以在Xcode中选择版本编辑器窗格,并显示每行的责任信息,例如谁进行了提交以及何时进行了提交。然而,在另一台笔记本电脑上,我总是会遇到错误 could not blame {file}. Error: fatal: no such ref: HEAD。我不确定这意味着什么或如何修复它。由于我经常进行拉取操作,所以仓库应该非常相似(除了.gitignore差异之类的东西)。因此,我不确定一个笔记本电脑上的.git文件夹是否存在微小差异。我知道HEAD是指某个提交的引用,但除此之外,我不确定如何修复这个问题。

“HEAD” 实际上不仅仅是一个提交,它是当前提交。必须始终存在一个当前提交,只有一种特殊情况除外:空仓库或孤立分支没有当前提交。孤立分支很少见(需要使用 git checkout --orphan),而且您可能会知道这是否是一个空仓库,因此这可能是某个 Xcode 的 bug。 - torek
我没有使用孤立分支,就像我所说的,如果我在两台笔记本电脑上从新拉取相同的分支,并且检出该分支,一个 Xcode 显示 blames,而另一个则显示此错误。 - Alex Bollbach
3个回答

0

你的代码库子文件夹中可能有第二个.git文件夹(至少这是我的情况)。Xcode不支持这种情况。

要解决这个问题,请前往你的代码库根目录:

cd ~/Development/repo

搜索子文件夹以查找迷路的仓库:

find . -name ".git"

如果输出中除了./.git以外还有其他内容,请将其删除:
rm -rf subfolder/some_folder/.git  

如果您此时已经运行了Xcode,请重新启动它,那么它应该可以按预期工作。

0

"无法归咎": 请关闭"归咎"编辑器。看起来您添加了一个尚未提交的新文件。因此,归咎编辑器没有数据可显示,并且会抛出"无法归咎"的错误。


0
Steps to fix not working blame for line in Xcode: -
1. Go to the project directory first.
2. Fist remove all the git process 
   use this command to find all git process `find . -name ".git"`
3. If there's anything other than ./.git in the output, remove it:
   use this command to remove `rm -rf subfolder/some_folder/.git` 
4. After that, you can delete your project folder and clone the same repo from 
   stash
   use git clone "ssh key for your repo"
5. After cloning the project, an open project you will able to see blame for a 
   line.

In my case this steps resolved the problem, I am not sure that will work for all but at least try it once.

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