如何git 将文件夹和文件移动到新文件夹并保留历史记录?

how to git move folder and files to new folder and keep history?

我想将其中的文件夹和文件移动到新文件夹。文件夹名称和文件名称都已更改。

Dir1
  file11
  file12

 TO

Dir2
  file21
  file22

我也想保留历史。

我可以一次性完成吗?或者我需要以下两个步骤?

git mv Dir1 Dir2
commit and push

git mv Dir2/file11 Dir2/file21
git mv Dir2/file11 Dir2/file22
commit and push

是的,您只需一次提交即可完成此操作:

git mv Dir1 Dir2
git mv Dir2/file11 Dir2/file21
git mv Dir2/file11 Dir2/file22
commit and push

您也可以在两次提交中执行此操作,并根据需要使用 git rebase -i HEAD~3 压缩它们。