Git:如何处理项目中的git库
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8897019/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Git: How to handle git libraries in project
提问by dhrm
I've a Xcode project which itself has Git Source Control. In a Librariesfolder I've cloned eight other Git project from GitHub. They are located inside my own Git repository and I've added all these libraries to my git in a commit.
我有一个 Xcode 项目,它本身有 Git 源代码控制。在Libraries文件夹中,我从GitHub克隆了另外八个 Git 项目。它们位于我自己的 Git 存储库中,并且我已在提交中将所有这些库添加到我的 git 中。
Instead of having the code of all these git libraries in my repository, is there a way to let git download their code from their repo when I make a clone of my repo? Or is it normal to include other git repos inside a project?
当我克隆我的存储库时,有没有办法让 git 从他们的存储库下载它们的代码,而不是在我的存储库中拥有所有这些 git 库的代码?或者在项目中包含其他 git repos 是否正常?
回答by Besi
Sure do the following:
一定要做到以下几点:
- Remove the 3rd-party-folder which you might have added already
Open your Terminal and execute the following commands
cd /path/to/your/main/repo git submodule add [email protected]:someuser/somerepo.git somerepo git commit -m "Added submodules"
Now instead of copying those files you'll have a reference to the other repository in your project:
- 删除您可能已经添加的 3rd-party-folder
打开终端并执行以下命令
cd /path/to/your/main/repo git submodule add [email protected]:someuser/somerepo.git somerepo git commit -m "Added submodules"
现在,您将拥有对项目中其他存储库的引用,而不是复制这些文件:
Edit:
编辑:
Now if you want to update the submodule to a more recent commit you can do the following:
现在,如果您想将子模块更新为更新的提交,您可以执行以下操作:
cd somerepo
git pull # You can also checkout a branch / tag etc.
cd ..
git add somerepo
git commit -m "Telling the main repo to update the reference to the referenced repo"
回答by gustavotkg
You can use git submoduleand clone repositories like this
您可以像这样使用git submodule和克隆存储库