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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3845234/
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:37:23  来源:igfitidea点击:

Viewing GIT history of moved files

git

提问by Pengin

Despite reading lots of other posts regarding GIT and moved files I still struggle to understand how to trace the full history. Doing gitk myfileas suggested hereseems to only show history until the previous move. I understand that GIT doesn't track files, only their content. So surely I should be able to view the full evolution of a file, even if it's been moved?

尽管阅读了许多关于 GIT 和移动文件的其他帖子,我仍然很难理解如何追踪完整的历史记录。这样gitk myfile的建议在这里似乎只能说明历史,直到前一个举动。我知道 GIT 不跟踪文件,只跟踪它们的内容。所以我当然应该能够查看文件的完整演变,即使它被移动了?

Can anyone direct me to a good yet simple example/tutorial?

任何人都可以指导我找到一个好的但简单的示例/教程吗?

I'd like to see an example where some files are moved around, changed and committed, then the history of a single file is displayed, moves and all. I've been looking at 'log' but that seems to concern checkins. Would still appreciate some advice, even if its says I'm somehow still thinking too much SVN.

我想看一个例子,其中一些文件被移动、更改和提交,然后显示单个文件的历史记录,移动等等。我一直在查看“日志”,但这似乎与签到有关。仍然会感谢一些建议,即使它说我不知何故仍在考虑太多 SVN。

回答by Greg Hewgill

Try using the --followoption to git log:

尝试使用该--follow选项git log

git log --follow file.txt

回答by isapir

Use git logwith both --followand --patchwhich will display the log with the rename from / rename to output. And don't forget the --before the file path.

使用git log与两个--follow--patch,这将显示日志与从/重命名,以输出该重命名。并且不要忘记--文件路径之前的。

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

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

例如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)

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)