将多个项目放入git存储库的最佳做法是什么? [英] What's the best practice for putting multiple projects in a git repository?

查看:90
本文介绍了将多个项目放入git存储库的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于某些原因,我只有一个存储库可供使用。但我有多个项目,包括Java项目,PHP脚本和Android应用程序。
现在我的问题是,我必须将它们放到每个项目的不同子文件夹中;而对于php项目和java项目,我使用不同的IDE。你知道,每个IDE都可以有一个工作区。



谁可以告诉我一个解决问题的最佳实践?



>解决方案1 ​​



一个存储库可以包含多个独立的分支,称为孤立分支。孤儿分支完全彼此分开;他们不共享历史。

  git checkout --orphan BRANCHNAME 

这会创建一个与您当前分支无关的新分支。每个项目都应该在自己的孤儿分支中。



无论出于何种原因,git需要在孤儿签出后进行一些清理。

  rm .git / index 
rm -r *

删除之前确保所有内容都已提交



一旦孤立分支干净,您可以正常使用它。 / p>

解决方案2



避免孤儿分支的所有麻烦。创建两个独立的存储库,并将它们推送到同一个远程。

 #repo 1 
git push origin master:master-1 $ b只需为每个回购使用不同的分行名称。
$ b#repo 2
git push origin master:master-2


As some reason, I only have one repository to use. But I have multiple projects including java projects, php scripts and android apps. Now my problems is, I have to put them to different sub-folders for each projects; and for php projects and java projects, I use different IDE. You know, each IDE can have a workspace of itself.

Who can tell me a best practice to solve the problem?

解决方案

While most people will tell you to just use multiple repositories, I feel it's worth mentioning there are other solutions.

Solution 1

A single repository can contain multiple independent branches, called orphan branches. Orphan branches are completely separate from each other; they do not share histories.

git checkout --orphan BRANCHNAME

This creates a new branch, unrelated to your current branch. Each project should be in its own orphaned branch.

Now for whatever reason, git needs a bit of cleanup after an orphan checkout.

rm .git/index
rm -r *

Make sure everything is committed before deleting

Once the orphan branch is clean, you can use it normally.

Solution 2

Avoid all the hassle of orphan branches. Create two independent repositories, and push them to the same remote. Just use different branch names for each repo.

# repo 1
git push origin master:master-1

# repo 2
git push origin master:master-2

这篇关于将多个项目放入git存储库的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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