Dan Bonachea建议在第一步中反转git log生成命令的循环:不是每个文件运行一次git log,而是在命令行上使用文件列表运行它一次,并生成一个统一的日志。这样修改多个文件的提交在结果中保持单个提交,所有新的提交都保持其原始的相对顺序。请注意,当重写(现已统一)日志中的文件名时,这还需要在下面的第二步中进行更改。
2.重组文件树并更新文件名
假设您想在另一个存储库中移动这三个文件(可以是同一个存储库)。
my_other_repo├── dirF│ ├── file55│ └── file56├── dirB # New tree│ ├── dirB1 # from subdir│ │ ├── file33 # from file3│ │ └── file44 # from file4│ └── dirB2 # new dir│ └── file5 # from file5└── dirH└── file77
commit c3ee8dfb01e357eba1ab18003be1490a46325992Author: John S. Gruber <JohnSGruber@gmail.com>Date: Wed Feb 22 22:20:19 2017 -0500
test rename again
diff --git a/yyy/power.py b/zzz/power.pysimilarity index 100%rename from yyy/power.pyrename to zzz/power.py
commit ae181377154eca800832087500c258a20c95d1c3Author: John S. Gruber <JohnSGruber@gmail.com>Date: Wed Feb 22 22:19:17 2017 -0500
rename test
diff --git a/power.py b/yyy/power.pysimilarity index 100%rename from power.pyrename to yyy/power.py
请注意,每当您使用diff时,这都有效,而不仅仅是git log。例如:
$ git diff HEAD c3ee8dfdiff --git a/power.py b/zzz/power.pysimilarity index 100%rename from power.pyrename to zzz/power.py
$ git merge -v masterAuto-merging singleMerge made by the 'recursive' strategy.one => single | 4 ++++1 file changed, 4 insertions(+)rename one => single (67%)