简体   繁体   English

在保留所有历史记录的同时,将git存储库移到同一路径下的子目录

[英]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.

相关问题 是否可以将一堆文件从一个git存储库移动到另一个git存储库,同时保留(大多数)历史记录? - Is it possible to move a bunch of files from one git repository to another while preserving (most) history? 如何在保留历史记录的同时将文件从一个git存储库移动到另一个存储库 - How to move a file from one git repository to another while preserving history GIT 拆分存储库目录保留*移动/重命名*历史 - GIT Split Repository directory preserving *move / renames* history 在移动GIT存储库时保留GIT提交的历史记录 - Preserving history of GIT commits while moving a GIT repository 如何移动文件(同时保留历史记录)并在git中创建具有相同名称的文件? - How to move a file (while preserving the history) and create one with the same name in git? 在保留历史记录的同时永久性地从git存储库中删除文件 - Permanentely remove files from a git repository while preserving the history 将 git 存储库及其所有历史记录导入现有 git 存储库 - Import a git repository with all its history into an existing git repository 将git存储库作为子文件夹移动到另一个存储库,同时保留历史记录 - Move a git repository to another repository as a subfolder while keeping history 将Git存储库从当前文件夹上移3个级别,保留历史记录并添加新文件 - Move Git repository up 3 levels from current folder, preserving history and adding new files git 将目录移动到另一个存储库,同时保留历史记录 - git move directory to another repository while keeping the history
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM