Git 责备显示没有历史记录

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/4638500/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 04:55:05  来源:igfitidea点击:

Git blame showing no history

gitwindows-subsystem-for-linuxmsysgitblame

提问by Assaf Lavie

When I run git blame on a file (using msysgit) I always get the following sort of printout:

当我对文件运行 git blame 时(使用 msysgit),我总是得到以下类型的打印输出:

00000000 (Not Committed Yet 2011-01-09 11:21:30 +0200   1) package co
00000000 (Not Committed Yet 2011-01-09 11:21:30 +0200   2) {
00000000 (Not Committed Yet 2011-01-09 11:21:30 +0200   3)      impor
00000000 (Not Committed Yet 2011-01-09 11:21:30 +0200   4)      impor
00000000 (Not Committed Yet 2011-01-09 11:21:30 +0200   5)      impor
00000000 (Not Committed Yet 2011-01-09 11:21:30 +0200   6)      impor
00000000 (Not Committed Yet 2011-01-09 11:21:30 +0200   7)      impor

i.e. it shows all lines as Not Yet Committed.

即它将所有行显示为尚未提交。

I tried this on many files, that have many commits - always the same results. I also tried using relative/full path, but it seems to make no difference.

我在许多文件上尝试了这个,有很多提交 - 总是相同的结果。我也尝试使用相对/完整路径,但似乎没有什么区别。

When I try to use TortoiseGit's blame it always shows every line as being last committed at the first commit:

当我尝试使用 TortoiseGit 时,它总是在第一次提交时将每一行显示为最后一次提交:

alt text

替代文字

even thought, as I've said, there are actually tens of commits in the history of these files..

甚至认为,正如我所说的,这些文件的历史记录中实际上有数十次提交..

Ideas?

想法?

Edit - More Info

编辑 - 更多信息

  • Git blame works fine on GitHub, where this repo is hosted.
  • It also works fine if I clone it to a linux machine and do the blame there
  • It seems that only on msysgit this doesn't work
  • Git blame 在托管此存储库的 GitHub 上运行良好。
  • 如果我将其克隆到 linux 机器并在那里承担责任,它也可以正常工作
  • 似乎只有在 msysgit 上这不起作用

回答by kusma

git blame file.txtblames the version of file.txt in your working copy. If file.txt has Windows-newlines (CRLF) in the repo and you have core.autocrlf = true, then every line of file.txt will be considered different and will be reported by git blameas not yet committed.

git blame file.txt指责你的工作副本中的 file.txt 版本。如果 file.txt 在 repo 中有 Windows-newlines (CRLF) 而你有core.autocrlf = true,那么 file.txt 的每一行都将被认为是不同的,并将被报告git blame为尚未提交。

The reason why git blame <my_branch>(or even better git blame HEAD, which works no matter what branch you're on) works, is that it doesn't blame the working copy version so there's no potential for lines not yet being committed.

之所以git blame <my_branch>(或者甚至更好git blame HEAD,无论您在哪个分支上都可以工作)有效的原因是,它不会归咎于工作副本版本,因此没有尚未提交的行的可能性。

回答by Assaf Lavie

Found the solution - very weird.

找到了解决方案 - 很奇怪。

If I run this:

如果我运行这个:

git blame file.txt

The history is broken, as posted above.

如上所述,历史已被打破。

If I do this instead:

如果我这样做:

git blame my_branch file.txt

It works!

有用!

This is very weird, because AFAICS the usage doesn't require a branch name:

这很奇怪,因为 AFAICS 的用法不需要​​分支名称:

$ git blame
usage: git blame [options] [rev-opts] [rev] [--] file

回答by VonC

Starting git 2.0.1 (June 25th, 2014), git blame should stop reporting all those "Not Yet Committed" lines.

从 git 2.0.1(2014 年 6 月 25 日)开始,git blame 应该停止报告所有那些“尚未提交”的行。

See commit 4d4813a(26 Apr 2014) by brian m. carlson (bk2204).
(Merged by Junio C Hamano -- gitster--in commit e934c67, 06 Jun 2014)

请参阅brian m 的提交 4d4813a(2014 年 4 月 26 日)。卡尔森 ( bk2204)
(由Junio C gitsterHamano合并-- --提交 e934c67 中,2014 年 6 月 6 日)

blame: correctly handle files regardless of autocrlf

If a file contained CRLFline endings in a repository with core.autocrlf=input, then blame always marked lines as "Not Committed Yet", even if they were unmodified.
Don't attempt to convert the line endings when creating the fake commit so that blame works correctly regardless of the autocrlfsetting.

blame: 正确处理文件,不管 autocrlf

如果文件CRLF在存储库中包含以结尾的行core.autocrlf=input,则blame 总是将行标记为“ Not Committed Yet”,即使它们没有被修改。
在创建假提交时不要尝试转换行尾,以便无论autocrlf设置如何,blame 都能正常工作。

回答by John Jacecko

Another possibility: case-sensitive filename typo

另一种可能性:区分大小写的文件名拼写错误

I had the same problem with git blame file.txt, then realized that I'd made a case-sensitive filename typo with file.txt

我在使用 git blame file.txt 时遇到了同样的问题,然后意识到我在 file.txt 中输入了区分大小写的文件名拼写错误

Changed it to File.txt (for example), and I got the expected results w/o having to specify my_branch: git blame File.txt

将其更改为 File.txt(例如),我得到了预期的结果,而不必指定 my_branch: git blame File.txt