[英]Move git repository to a subdirectory in the same path while preserving all of its history
I have a git repository with >100 commits that I initialized awhile back in the following path: 我有一个> 100次提交的git存储库,我在以下路径中对其进行了初始化:
/Users/myusername/
However, all of my commits are actually for files in the path: 但是,我所有的提交实际上都是针对路径中的文件的:
/Users/myusername/excess/folders/not/requiring/version/control/project_root/
I should have initialized the repository in project_root/
, because I don't need to version control anything in the upper directories. 我应该已经在project_root/
初始化了存储库,因为我不需要版本控制上层目录中的任何内容。
Is there any easy way of changing the path of my repository so that the top level of the repository is project_root/
while also preserving my version history as it is? 有什么简单的方法可以更改存储库的路径,以使存储库的最高级别为project_root/
同时也可以按原样保留我的版本历史记录? Are there any extra steps to get this reflected in my remote repository as well or do I just commit and push after making the change? 是否还有其他步骤可将其反映在我的远程存储库中,还是在更改后我只是提交并推送?
If something goes wrong, you can delete the copied .git*
files and start over. 如果出现问题,可以删除复制的.git*
文件并重新开始。 Here is what you can do: 您可以执行以下操作:
$ cp -r .git* path/to/project_root/
$ cd path/to/project_root/
$ git add -A .
When you call git status
, all you should see are renames and removes now. 调用git status
,您应该看到的只是重命名和立即删除。 If all looks good, you can delete .git*
in the previous root. 如果一切正常,则可以删除前一个根.git*
中的.git*
。
Also beware that any files existed in history will remain there, that requires another operation to clean up if you have credential files etc. 还请注意,历史记录中存在的任何文件都将保留在其中,如果您有凭据文件等,则需要执行另一项操作来清理。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.