javascript - Git 子模块、切换分支和包含外部 JS 依赖项的推荐方式(天哪)

标签 javascript git git-submodules

我有一个 Ruby on Rails 项目(使用 git 进行版本控制),其中包含许多存在于各种公共(public) 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)

最佳答案

子模块的替代方案是 subtree merge strategy .从该页面复制(它有更多信息,这纯粹是为了引用):

In this example, let’s say you have the repository at /path/to/B (but it can be an URL as well, if you want). You want to merge the master branch of that repository to the dir-B subdirectory in your current branch.

Here is the command sequence you need:

$ 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

我个人觉得这很麻烦(我更喜欢子模块,即使有你提到的问题),尽管很多人都发誓。

关于javascript - Git 子模块、切换分支和包含外部 JS 依赖项的推荐方式(天哪),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5383863/

相关文章:

linux - 如何在 Linux 服务器上设置 Git?

git - 无法通过 ssh 连接到 github;权限被拒绝(公钥)

Git 嵌套的子模块和依赖项

javascript - 如何更改 javascript for 循环条件?新手问题

javascript - 在属性更新后更新用户上下文 - AWS Amplify

git - 是否有用于推送 git 的排除文件等效项?

git - 是否可以让 Git 知道现有的 .gitmodules 文件?

git - 为什么 git 无法为给定的提交获取特定的有效子模块以及如何修复它?

javascript - 在 jquery 中单击按钮获取父级(仅属于特定类)的索引

javascript - Reactjs:类/原型(prototype)在我们的应用程序中有任何位置吗?