查看已移动文件的GIT历史记录


79

尽管阅读了很多有关GIT和移动文件的其他文章,但我仍然很难理解如何跟踪完整的历史记录。这样gitk myfile的建议在这里似乎只能说明历史,直到前一个举动。我知道GIT不会跟踪文件,只会跟踪文件的内容。因此,即使文件已移动,我当然也应该能够查看文件的完整演变?

谁能将我引到一个不错而又简单的示例/教程?

我想看一个示例,其中一些文件被移动,更改和提交,然后显示,移动和全部显示单个文件的历史记录。我一直在看“日志”,但这似乎与签到有关。仍然会喜欢一些建议,即使它说我以某种方式仍在考虑太多SVN。


Answers:


110

尝试将--follow选项用于git log

git log --follow file.txt

7
请注意,目前该--follow机制是固定的,在某些极端情况下不起作用。
JakubNarębski2010年

2
如果得到fatal: ambiguous argument 'file.txt': unknown revision or path not in the working tree,请尝试git log --follow-file.txt
nealmcb

2
@nealmcb-- 在路径/到/文件之前添加了恰好缺少的内容。添加后效果很好。谢谢!
bkidd

1

git log--follow和一起使用--patch,它将显示带有从/重命名为输出的日志。并且不要忘记--文件路径之前的。

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

例如testdir/more-testing.txt,我系统上的文件历史记录显示:

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)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.