【问题标题】:Git submodules, switching branches, and the recommended way to include external JS dependencies (oh my)Git 子模块、切换分支以及包含外部 JS 依赖项的推荐方式(天哪)
【发布时间】:2011-08-16 21:15:57
【问题描述】:

我有一个 Ruby on Rails 项目(使用 git 进行版本控制),其中包含许多外部 JavaScript 依赖项,这些依赖项存在于各种公共 GitHub 存储库中。将这些依赖项包含在我的存储库中(当然,除了手动复制它们)以允许我控制它们何时更新的最佳方式是什么?

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)

【问题讨论】:

    标签: javascript git git-submodules


    【解决方案1】:

    子模块的替代方案是subtree merge strategy。从该页面复制(它有更多信息,仅供参考):

    在这个例子中,假设你有 /path/to/B 的存储库(但它 如果需要,也可以是 URL)。 您要合并的主分支 该存储库到 dir-B 当前分支中的子目录。

    这是您需要的命令序列:

    $ git remote add -f Bproject /path/to/B 
    $ git merge -s ours --no-commit Bproject/master <2> 
    $ git read-tree --prefix=dir-B/ -u Bproject/master
    $ git commit -m "Merge B project as our subdirectory"
    $ git pull -s subtree Bproject master
    

    我个人觉得这很繁琐(我更喜欢子模块,即使你提到的问题也是如此),尽管很多人都信誓旦旦。

    【讨论】:

      【解决方案2】:

      this blogthis post 都报告相同的警告:

      这是因为目前不支持子模块删除。已经有很多讨论如何让 git 处理得更好,但到目前为止还没有人实现它。但它在我的待办事项清单上,敬请期待……

      (当时 Jens Lehmann 说,2010 年 11 月)。

      目前(2011 年 3 月),我没有看到(或错过)这方面的任何改进。

      git checkout -f -q develop 在你的情况下会做什么?

      【讨论】:

        猜你喜欢
        • 2023-03-03
        • 2013-11-05
        • 2021-12-25
        • 2013-04-17
        • 2014-02-17
        • 2014-02-10
        • 2014-05-16
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多