我已经创建了一个带有子模块的git存储库.我能够告诉子模块本身更改其远程存储库路径,但我不知道如何告诉父存储库如何更改子模块的远程存储库路径.
如果我有点不幸并且必须手动操作,我不会感到惊讶,因为即使删除子模块也不容易.
我有一个子模块的项目 lib/three20
我的.gitmodule
文件看起来像这样:
[submodule "lib/three20"]
path = lib/three20
url = git://github.com/facebook/three20.git
Run Code Online (Sandbox Code Playgroud)
我过去克隆过这个没有错误,(git submodule init
接下来是a git submodule update
)并且它已经工作了一段时间.
我试图将其克隆到一台新机器,现在我收到此错误git submodule init
:
No submodule mapping found in .gitmodules for path 'Classes/Support/Three20'
Run Code Online (Sandbox Code Playgroud)
该路径只是Xcode中的一个空文件夹,用于存放其他目录中的项目.它不是.gitmodules
文件的一部分,所以我看不到它从哪里获得这条路径.
有任何想法吗?
在Linux上使用Git 1.8.1.1.存储库如下所示:
master
book
Run Code Online (Sandbox Code Playgroud)
子模块创建如下:
$ cd /path/to/master
$ git submodule add https://user@bitbucket.org/user/repo.git book
Run Code Online (Sandbox Code Playgroud)
该book
子模块是干净的:
$ cd /path/to/master/book/
$ git status
# On branch master
nothing to commit, working directory clean
Run Code Online (Sandbox Code Playgroud)
另一方面,主人显示书子模块有"新提交":
$ cd /path/to/master/
$ git status
# On branch master
# 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: book (new …
Run Code Online (Sandbox Code Playgroud) 我有一个包含许多子模块的项目.我想用以下命令遍历每个子模块:
git submodule foreach npm install
我希望脚本继续循环遍历每个子模块,即使一个子模块返回错误(非零返回码).目前,在任何子模块中运行此命令的非零返回码将导致git停止在其余子模块上循环.
关于如何实现这一目标的任何建议?
“git Remote get-url origin”可用于获取远程位置。如何对所有子模块执行相同的操作?
当我们在git存储库中有很多(比如20个)子模块时,我们可以像这样安装(和更新)它们:
git submodules update --init --recursive
Run Code Online (Sandbox Code Playgroud)
Git尝试在此命令后下载每个子模块(递归).如果我们想让一些子模块可选(如插件)怎么办?
我们怎样才能让git跳过默认下载这些可选子模块,并在我们标记这个子模块时处理为通常的子模块"好的,从现在开始使用"?
git ls-files
Run Code Online (Sandbox Code Playgroud)
还列出了子模块。
使用:列出 git 存储库中的子模块以及如何从另一个文件 A 中删除出现在文件 B 上的行?我可以:
git ls-files | grep -Fxvf <(git submodule status | cut -d' ' -f3)
Run Code Online (Sandbox Code Playgroud)
或更详细和通用的:
git ls-files | while IFS='' read -r file; do
if [ -f "$file" ]; then
echo "$file"
fi
done
Run Code Online (Sandbox Code Playgroud)
使用一些 git 命令/标志有更短的方法吗?
我是一个患有先前svn经验的git新手.我的很多项目都使用自己库中的代码,所以很自然地我想从git中获得一些"类似于外部"的功能.我目前正在尝试使用子模块.
但是如果以错误的方式使用子模块(据我所知),子模块可能会带来很大的痛苦(例如,更改子模块中的文件并忘记推送它们,或者忘记提交它们).
如果我将子模块中的所有文件设为只读怎么办?这足以防止意外更改.如果我真的想改变一些东西,我应该去改变原来的回购.
所以,我的问题是:
编辑:我希望可以通过git hook实现,但我不确定如何.我第一次克隆回购时不能使用客户端挂钩,是吗?
EDIT2:在SRobertz的帮助下,我能够拿出一个结账后的钩子:
echo "you just checked out: $*"
echo "submodules:"
for p in `grep path .gitmodules | sed 's/.*= //'`; do # get submodules list
echo "making submodule directory $p read-only"
chmod -R a-w $p;
SAVEIFS=$IFS
IFS=$(echo -en "\n\b") #set delimeter to \n\b to handle whitespaces in filenames
for f in `ls $p`; do #get files in submodule dir
echo "making file $f in directory $p read-only"
chmod -R a-w $p\\$f;
done
IFS=$SAVEIFS …
Run Code Online (Sandbox Code Playgroud)