我最近将一些插件转换为子模块,并意识到当你"git clone"一个存储库时,子模块目录将为空.这对于共同开发人员初始化他们的子模块和更新是有意义的.
但是,当我使用capistrano部署时,子模块代码显然不会被部署,从而导致问题.我可以进入发布分支并初始化并更新那里的模块,但这显然不是一个理想的解决方案.
有没有人有关于如何处理这个问题的建议?它是否像capistrano任务一样简单?
在生产方面,我有点像菜鸟.
谢谢!
有很多网页在那里暗示让svn外部看起来像git子模块的hackish方法.我已经读过一些关于差异的说法,但这似乎不是很基础:
Git子模块链接到另一个项目的存储库中的特定提交,而svn:externals总是获取最新的修订.
为什么这种差异会使它们根本不相容?我们可以假设没有合理的默认值,例如大多数svn:externals指向永不移动的标签吗?
我有一个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 …Run Code Online (Sandbox Code Playgroud) 我使用git通过https克隆一个repo因此:
git clone https://username:password@alocation/git/repo.git
Run Code Online (Sandbox Code Playgroud)
这很好,但它有大量的子目录要克隆,所以我使用该--recursive选项.
这里的问题是,对于顶级,它需要指定用户名和密码,但是对于每个子仓库,它再次询问详细信息,因此我得到以下内容:
C:>git clone --recursive https://username:password@alocation/git/repo.git
Cloning into repo...
remote: Counting objects: 15, done.
remote: Compressing objects: 100% (15/15), done.
remote: Total 15 (delta 8), reused 0 (delta 0)
Unpacking objects: 100% (15/15), done.
Submodule 'sub1' (https://alocation/git/repo.sub1) registered for path 'sub1'
Submodule 'sub2' (https://alocation/git/repo.sub2) registered for path 'sub2'
Submodule 'sub3' (https://alocation/git/repo.sub3) registered for path 'sub3'
Submodule 'sub4' (https://alocation/git/repo.sub4) registered for path 'sub4'
Cloning into sub1...
Username:
Password:
remote: Counting objects: 10, done.
remote: Compressing …Run Code Online (Sandbox Code Playgroud) 我有一个带有附加工作树的git存储库,我正在推送到远程的裸仓库.存储库包括子模块.
在远程端:我将repo检查到git checkout -f具有set GIT-DIR和GIT-WORK-TREEenv vars 的工作树.
在工作树中,我现在看到所有预期的文件和子模块的空目录('MySubmodule').
然后我做:
git submodule init
git submodule update
Run Code Online (Sandbox Code Playgroud)
这个错误的消息如下:
working tree '../../workTree/' already exists
Clone of 'git@github.com:user/MySubmodule.git' into submodule path 'MySubmodule' failed
Run Code Online (Sandbox Code Playgroud)
空的子模块目录现在也从工作树中"消失"了......
我不知道我在哪里出错了,基本上我只想查看子模块文件,就像我使用'git submodule update'一样.
我在一个大型回购团队工作.最近我们决定将其中一个文件夹移动到自己的子模块中
-- aaa
-- .git
-- bbb
-- ccc
-- www # this folder is going into its own repo.
Run Code Online (Sandbox Code Playgroud)
我按照说明将www文件夹过滤到这里列出的自己的repo:Detach(move)子目录到单独的Git存储库中.我把www文件夹移出了aaa回购.
我通过运行以下命令从主分支中删除了该目录:
$ cd aaa
$ git checkout master
$ git rm -rf www
$ git commit -m "remove the www/ folder from the aaa repo."
Run Code Online (Sandbox Code Playgroud)
所以现在在master上,树看起来像这样:
-- aaa
-- .git
-- bbb
-- ccc
Run Code Online (Sandbox Code Playgroud)
我想www通过运行添加为子模块:
$ cd aaa
$ git checkout master
$ git submodule add git@bitbucket.org:kevinburke/www.git www
Cloning …Run Code Online (Sandbox Code Playgroud) 我更改了git子模块的提交指针:
% git status
# On branch fix
# Your branch is behind 'origin/fix' by 1 commit, and can be fast-forwarded.
#
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: app/lib (new commits)
#
no changes added to commit (use "git add" and/or "git commit -a")
Run Code Online (Sandbox Code Playgroud)
但是当我这样做时git checkout,没有任何改变:
% git checkout -- app/lib && …Run Code Online (Sandbox Code Playgroud) 我设置了一些git钩子来gulp在预提交上运行一些命令.我基本上跑jshint/ plato.我基本上想要绕过这两种情况:
plato gulp命令在源上运行分析并生成跟踪复杂性的/ reports /目录.如果我们在修补程序分支上执行此操作,则在将它们合并回开发时会导致合并冲突.这里足够的说话是简单的钩子:
#!/bin/sh
if git diff --cached --name-only --diff-filter=ACM | grep '.js$' >/dev/null 2>&1
then
git stash -q --keep-index
./node_modules/.bin/gulp jshint
RESULT=$?
git stash pop -q
[ $RESULT -ne 0 ] && exit 1
git stash -q --keep-index
./node_modules/.bin/gulp plato
git add report/
git stash pop -q
fi
exit 0
Run Code Online (Sandbox Code Playgroud)
现在的问题是,如果我在"报告"上有合并冲突,我解决了合并All conflicts fixed but you are still merging.,然后提交它再次运行分析并分阶段提交,当它提交时抛出一个错误:
/Users/Nix/work/project/.git/modules/somesubmodule/MERGE_HEAD'用于阅读:没有这样的文件或目录.
该目录确实存在,但没有合并头...
我有以下git结构
- git-repo a
-- subdirectory 2015
--- git-submodule b
-- git-submodule c
--- git-submodule d
Run Code Online (Sandbox Code Playgroud)
我想将git子模块c移动到文件夹2015.我知道"脏方法"这样做(涉及修改.git/config并更改.git/modules文件中的几个文件中的gitdir)
我最近读到git mv应该能够做到这一点,即运行
git mv c 2015/
Run Code Online (Sandbox Code Playgroud)
这适用于没有嵌套子模块的存储库(在我的例子中为d).但是,当我在我的目录上运行此命令时,我收到的错误就像
fatal: Not a git repository: d/../../.git/modules/c/modules/d
fatal: 'git status --porcelain' failed in submodule 2015/c
Run Code Online (Sandbox Code Playgroud)
(注意,执行上述移动后,git状态会出现此错误)
是否有人知道一个干净的方法来执行此移动(即,不涉及手动更改.git/modules文件中的路径)?
编辑:(6/10/2015)
我目前最好的解决方案是不涉及对任何git配置文件的修改(首先要确保对d的所有更改都已提交并推送到某处)
rm c/d -rf
git mv c 2015
cd 2015/c
git submodule update
Run Code Online (Sandbox Code Playgroud)
编辑:(8/10/2015)
一个更少侵入性的解决方法
git mv c 2015
rm 2015/c/d/.git
cd 2015/c
git submodule update
Run Code Online (Sandbox Code Playgroud)
编辑:(21/9/2018)
自从git版本2.19.这已得到修复,并且git mv表现如预期.
我有一个很长的回购列表,我试图通过使它们成为所有子模块而成为一个父回购.
我已尝试将它们.gitmodules手动添加到手机中.git/config,但它似乎无法正常工作.
我也试过运行git submodule sync和git submodule update --init等,但没有运气.
有没有办法欺骗git认为我的项目有它的所有(~30K)子模块,而不需要实际克隆它们?
git ×10
git-submodules ×10
capistrano ×1
deployment ×1
git-mv ×1
git-svn ×1
githooks ×1
javascript ×1
plugins ×1
svn ×1