查看移动文件的 Git 历史记录

尽管读了很多关于 GIT 和移动文件的其他文章,我仍然很难理解如何跟踪完整的历史。按照建议的 给你gitk myfile似乎只能显示上一步之前的历史。我知道 GIT 不跟踪文件,只跟踪文件的内容。那么,即使文件被移动了,我也应该能够查看文件的完整演变过程吗?

有人能告诉我一个简单的例子/教程吗?

我想看一个例子,其中一些文件被移动,更改和提交,然后单个文件的历史记录显示,移动和所有。我一直在查看“日志”,但这似乎与签到有关。我还是很感激你的建议,即使它说我还是想了太多 SVN。

23460 次浏览

Try using the ABC0 option to git log:

git log --follow file.txt

Use git log with both --follow and --patch which will display the log with the rename from / rename to output. And don't forget the -- before the file path.

git log --follow --patch -- path/to/file.ext

For example the history of file testdir/more-testing.txt on my system shows:

Date:   Wed Mar 18 14:48:07 2020 -0700


renamed file


diff --git a/testdir/testing.txt b/testdir/more-testing.txt
similarity index 100%
rename from testdir/testing.txt
rename to testdir/more-testing.txt


commit feb58d3ab8e8ce940f80499df0c46e8fc8caf679
Author: Igal <redacted>
Date:   Wed Mar 18 14:47:18 2020 -0700


moved test.txt to subdirectory and renamed


diff --git a/test.txt b/testdir/testing.txt
similarity index 100%
rename from test.txt
rename to testdir/testing.txt


commit 34c4a7cebaeb0df5afb950972d69adea6b1a7560
Author: Igal <redacted>
Date:   Wed Mar 18 14:45:58 2020 -0700


added test.txt


diff --git a/test.txt b/test.txt
new file mode 100644
index 000000000..0527e6bd2
--- /dev/null
+++ b/test.txt
@@ -0,0 +1 @@
+This is a test
(END)