gpt4 book ai didi

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

转载 作者:IT王子 更新时间:2023-10-29 00:44:08 26 4
gpt4 key购买 nike

我有一个 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com