如何解决Git/Github 将子目录重定向到其他存储库
我将项目的子模块保存在不同的存储库中。
我在主项目的 Modules 文件夹中托管子模块。
子模块在根项目的 .gitignore` 文件中被忽略。
没关系,但我想在 github 上创建指向子模块的链接。
我尝试使用子模块。但是,如果我使用子模块,我猜文件夹内容 (Modules/..
) 必须是空的。
我该怎么做?
我的本地工作区:
RootFolder << user/RootFolder
├── .git
├── README.md
├── .gitignore
├── composer.json
└── Modules
├── Module1 << user/Module1
│ ├── .git
│ ├── README.md
│ └── composer.json
└── Module2 << user/Module2
├── .git
├── README.md
└── composer.json
RootFolder/.gitignore
内容:
/Modules
在 Github 上看起来是这样的。 (理应如此)
user/RootFolder
├── README.md
└── composer.json
但是,我想创建与被忽略文件夹同名的链接:
user/RootFolder
├── .gitignore
├── Modules
│ ├── Module1 >> Redirect to https://github.com/user/Module1 (How can I do that?)
│ └── Module2 >> Redirect to https://github.com/user/Module2 (How can I do that?)
├── README.md
└── composer.json
解决方法
要转换您现有的文件夹结构以使用适当的子模块:
-
确保父存储库和模块存储库都没有任何更改。换句话说,请确保
git status
告诉您您有nothing to commit,working tree clean
。 -
将当前模块存储库移开,以进行备份。换句话说,
mv Modules/Module1 Modules/Module1.bak
。 -
将其添加为子模块:
git submodule add -f https://github.com/path_to/module1 Modules/Module1
。需要-f
,因为Modules
仍然存在于您的.gitignore
中。 -
确保文件结构符合您的喜好。运行构建、测试等。运行
git status
以确保.gitmodules
文件和模块本身显示为阶段性更改。当您对一切都感到满意时提交更改。 -
从第一步开始重复,直到您转换了所有子模块。
-
从
Modules
目录中删除备份模块文件夹。 -
从您的
/Modules
中删除.gitignore
。
恭喜(???)你现在有了子模块。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。