Git 子模块、切换分支以及包含外部 JS 依赖项的推荐方法(天哪)
我有一个 Ruby on Rails 项目(使用 git 进行版本控制),其中包含多个公共 GitHub 存储库中存在的许多外部 JavaScript 依赖项。将这些依赖项包含在我的存储库中(当然,除了手动复制它们)以允许我控制它们何时更新的最佳方式是什么?
git 子模块似乎是完美的方法,但在多个分支之间切换时会导致问题,其中许多分支不包含相同的子模块。
如果 git 子模块是最好的方法,我想我真正的问题是:如何在许多分支中使用子模块而不总是遇到这个问题:
my_project[feature/new_feature√]$ git submodule update
Cloning into public/javascripts/vendor/rad_dependency...
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 34 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (34/34), 12.21 KiB, done.
Resolving deltas: 100% (9/9), done.
Submodule path 'public/javascripts/vendor/rad_dependency': checked out '563b51c385297c40ff01fd2f095efb14dbe736e0'
my_project[feature/new_feature√]$ git checkout develop
warning: unable to rmdir public/javascripts/milkshake/lib/cf-exception-notifier-js: Directory not empty
Switched to branch 'develop'
my_project[develop⚡]$ git status
# On branch develop
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# public/javascripts/milkshake/lib/cf-exception-notifier-js/
nothing added to commit but untracked files present (use "git add" to track)
I have a Ruby on Rails project (versioned with git) that includes a number of external JavaScript dependencies that exist in various public GitHub repositories. What's the best way to include those dependencies in my repository (aside, of course, from just manually copying them in) in a way that allows me to control when they get updated?
git submodules seem like the perfect way to go, but it causes problems when switching among several branches, many of which don't contain the same submodules.
If git submodules are the best way to do it, I suppose my real question is: How can I use submodules among many branches without running into this problem all the time:
my_project[feature/new_feature√]$ git submodule update
Cloning into public/javascripts/vendor/rad_dependency...
remote: Counting objects: 34, done.
remote: Compressing objects: 100% (29/29), done.
remote: Total 34 (delta 9), reused 0 (delta 0)
Receiving objects: 100% (34/34), 12.21 KiB, done.
Resolving deltas: 100% (9/9), done.
Submodule path 'public/javascripts/vendor/rad_dependency': checked out '563b51c385297c40ff01fd2f095efb14dbe736e0'
my_project[feature/new_feature√]$ git checkout develop
warning: unable to rmdir public/javascripts/milkshake/lib/cf-exception-notifier-js: Directory not empty
Switched to branch 'develop'
my_project[develop⚡]$ git status
# On branch develop
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# public/javascripts/milkshake/lib/cf-exception-notifier-js/
nothing added to commit but untracked files present (use "git add" to track)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
子模块的替代方案是 子树合并策略。从该页面复制(它有更多信息,仅供参考):
我个人觉得这很繁琐(我更喜欢子模块,即使有您提到的问题),尽管很多人都坚信它。
An alternative to submodules is the subtree merge strategy. Copied from that page (it has more info, this is purely for reference):
I personally find this fiddly (I prefer submodules, even with the issus you've mentioned), although a lot of people swear by it.
两者这个博客和这篇文章报告了相同的警告:
(Jens Lehmann 当时说道,2010 年 11 月)。
现在(2011 年 3 月),我没有看到(或者我错过了)这方面的任何改进。
在您的情况下,
git checkout -f -qdevelopment
会做什么?Both this blog and this post reports the same warning:
(said Jens Lehmann at the time, November 2010).
Right now (March 2011), I don't see (or I missed) any improvment on that front.
What would a
git checkout -f -q develop
do in your case?