Git使用子树或子模块来管理外部资源 [英] Git using subtree or submodule to manage external resources

查看:811
本文介绍了Git使用子树或子模块来管理外部资源的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读了很多关于git submodule应该是多么糟糕的问题,但我不确定这是否只是感觉它受到限制或者它有严重问题的人的呻吟(特别是关于我的用例)。

p>

我只是希望在我的回购中包含不同的回购,例如

 网站/ 
libs /
js /
fs-slides [external]
fs-dialog [external]

,并且可以轻松更新这些回购协议。据我所知,从回购中只包含一个文件是不太可能的,对吧? (但没关系。)



我应该使用子模块吗?

或者是否有任何问题?或者是子树更容易?

解决方案

子模块非常适合您的情况,尤其是因为您不介意包含这些subrepos在他们自己的子目录中。



使用子模块的主要严重问题是在进行更新时更新它们,如如何做git submodule工作



如果您在子模块中提交时忘记设置分支,则所述提交将在分离的HEAD上进行,并且正在进行的更改将在下一个 git子模块更新(如果为子模块回购激活,您可以通过 reflog 获取它们)。

然后,如迈克尔

I read much about how awful the git submodule is supposed to be, but I am not sure if that is just the groaning of people who feel it limits or if it has serious issues (especially concerning my use case).

I just want to include different repos into my repo like this

website/
 libs/
  js/
   fs-slides [external]
   fs-dialog [external]

and have to possibility to update those repos easily. As far as I understand there is no easy possibility of including just one file from a repo, right? (But that's okay.)

Should I use submodules for this?
Or are there any problems with it? Or is subtree much easier?

解决方案

Submodule is well-suited to your case, especially since you don't mind included those subrepos in their own subdirectory.

The main serious issue you could have using submodules is when updating them while having updates in progress, as described in "how exactly does git submodule work":

If you forget to set a branch when making commits in a submodules, said commits will be made on a detached HEAD, and those changes in progress will be lost at the next git submodule update (you can get them back through the reflog, if activated for your submodule repo).

Then, as Michael comments, and as I detail in the link above, you need to push the submodule to its own upstream before commit and pushing the parent repo (to avoid pushing unpublish submodule commits)

这篇关于Git使用子树或子模块来管理外部资源的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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