该死的,没有历史记录

当我在一个文件上运行 git  (使用 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

也就是说,所有行都显示为“尚未提交”。

我在很多文件上都试过这个方法,这些文件有很多次提交——结果总是一样的。我还尝试使用相对/完整路径,但似乎没有什么区别。

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

alt text

即使如我所说,在这些文件的历史中有数十次提交。

有什么想法吗?

编辑-更多资讯

  • Git Blame 在 GitHub 上运行良好,这个回购站点就设在这里。
  • 如果我把它克隆到一台 linux 机器上,然后在那里推卸责任,它也能正常工作
  • 似乎只有在 msysgit 上才不管用
15005 次浏览

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:

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

git blame file.txt blames 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 blame as not yet committed.

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.

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

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

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

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

blame: correctly handle files regardless of autocrlf

If a file contained CRLF line 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 autocrlf setting.


radon8472 adds in the comments:

the answer was git blame -w (iggnore whitespace).
The reason was that the textconv for my blamed file was working with windows linebreaks, and git blame seems to not like it, as mentioned in kusma's answer.