您提到的解决方案应该可以使用,因为git首先根据文件的哈希值跟踪更改,然后根据文件的位置跟踪更改。
如果在移动文件的过程中更改了文件的内容,则此方法将无效。
大写情况下,尝试一下,如果它不起作用,则可以还原更改,然后再将更改推送到主存储库:)。这就是我非常喜欢git的原因之一。
编辑
我忘了提到要在重命名后看到更改,您需要使用'--follow'参数。检查这个例子
首先,我创建了一个新的git repo
94:workspace augusto$ mkdir gittest
94:workspace augusto$ cd gittest/
94:gittest augusto$ git init
Initialized empty Git repository in /Volumes/Data/dev/workspace/gittest/.git/
然后在文件夹/测试中创建一个文件
94:gittest augusto$ mkdir folder
94:gittest augusto$ vi folder/test
94:gittest augusto$ git add folder/test
94:gittest augusto$ git commit -am "added file"
[master (root-commit) 7128f82] added file
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 folder/test
然后将文件移动到newfolder / test
94:gittest augusto$ mkdir newfolder
94:gittest augusto$ mv folder/test newfolder/
94:gittest augusto$ git add newfolder/test
94:gittest augusto$ git commit -am "moved/renamed file"
[master 4da41f5] moved/renamed file
1 files changed, 0 insertions(+), 0 deletions(-)
rename {folder => newfolder}/test (100%)
并git log --follow newfolder/test
显示完整的历史记录(我添加了参数-p以显示更多信息,例如路径)。
94:gittest augusto$ git log --follow -p newfolder/test
commit 4da41f5868ab12146e11820d9813e5a2ac29a591
Author: Augusto Rodriguez <xxxx@gmail.com>
Date: Sat Aug 20 18:20:37 2011 +0100
moved/renamed file
diff --git a/folder/test b/newfolder/test
similarity index 100%
rename from folder/test
rename to newfolder/test
commit 7128f8232be45fd76616f88d7e164a840e1917d5
Author: Augusto Rodriguez <xxxx@gmail.com>
Date: Sat Aug 20 18:19:58 2011 +0100
added file
diff --git a/folder/test b/folder/test
new file mode 100644
index 0000000..3b2aed8
--- /dev/null
+++ b/folder/test
@@ -0,0 +1 @@
+this is a new file
我希望这有帮助!
git mv
移动。您可以git add
使用添加新文件后进行检查git status
。