在目录中创建一个新的git仓库 [英] Create a new git repo off of a branch in a directory

查看:101
本文介绍了在目录中创建一个新的git仓库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在我的Git仓库中,我有一个目录A.在分支中,我在A下创建了一个目录B.有没有办法在目录B中创建/初始化一个新的Git仓库?如果要复制该目录,清除所有.git数据,并在该新复制的目录中执行git init,那么这个技巧是否有用?请注意,您可以拆分一个git repo,使用git filter-branch在自己的repo中创建一个子目录。

请参阅如何将存储库拆分为更小的原子库?

(和



重写库看起来好像 foodir / 是它的项目根目录,并放弃所有其他历史记录:




  git filter-branch --subdirectory-filter foodir  -  --all 

这将允许您保留历史记录,但会重写您的原始回购协议(意味着其他贡献者你必须将你的克隆重置到你的新历史记录中)。

完成后,你可以将你的子目录所在的克隆新的回购:嵌套回购被父母忽略repo。

或者您可以将该子回购作为一个
子模块


In my Git repo, I have a directory A. In a branch, I've created a directory B under A. Is there a way to create/initialize a new Git repo in directory B? Would copying that directory, clearing all of the .git data, and do a git init in that new copied directory do the trick?

解决方案

Note that you can split a git repo, making a subdirectory in its own repo with git filter-branch.

See "How can I split a repository apart into smaller atomic repositories?"
(and "Detach subdirectory into separate Git repository":

To rewrite the repository to look as if foodir/ had been its project root, and discard all other history:

   git filter-branch --subdirectory-filter foodir -- --all

That would allow you keep the history, but will rewrite the one of your original repo (meaning other contributors would have to reset their clone to your new history).

Once done, you can clone that new repo right where your subdirectory were: nested repos are ignored by the parent repo.
Or you can include that sub-repo as a submodule.

这篇关于在目录中创建一个新的git仓库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆