克隆超级项目后如何保持git子模块分支状态? [英] how to keep git submodule on-branch status after cloning superproject?
问题描述
我正在测试新的 git submodule add -b
特性(在git 1.8.2之后),它创建了涉嫌跟踪分支而不是提交的子模块。我正在使用 git 1.8.4.msysgit.0
。子模块的分支跟踪功能似乎在原来的超级项目中运行良好,但只要超级项目被克隆就会失败。更具体地说:
我做的是典型的,大致如下:
1。创建一个git repo(称为common):...
2.创建一个主要项目(称为main),它使用通用的库/子模块。
mkdir main&& cd main
git init
git子模块add -b master url_to_common.git
git commit -m初始提交
cd常用
git状态
如上所述,添加的子模块跟踪子模块回购的主分支。我得到了:
$ b $ pre $ #在分支master
上没有提交,工作目录干净
另外,如果我做了 git pull
或 git push
,我得到
已经是最新的。
一切都是最新的
。
然而,如果我以任何方式克隆 我用来克隆和检查子模块的命令为: 我得到了: 我也试过 同样的事情发生在 我的问题是,如何在克隆后保持分支跟踪功能超级项目。我特别感兴趣的是使 注意:在分支丢失后指定分支(例如, Git子模块:指定分支/标记)不是我正在寻找的,因为 对于存在这个问题的其他人: 如答案所述,您的子模块跟踪提交。这实际上不是问题,子模块在单个时间点(即提交)表示外部依赖关系,而不是活跃的开发流(分支)。你可以手动更新这个依赖关系(理论上,只有在master分支上) 在提交时你只关心你的分支。承诺如果不在一个分支上,就会造成一个分离的头脑,而且开始很容易让你的团队失去工作。 我在我们的工作室解决了这个问题,如果不在分支上,提交钩拒绝提交: 这个钩子与这个BAT一起致力于超级回购(是的,我知道,对不起)scr ipt安装钩子 新的克隆需要运行该脚本,但这并不完美,但最接近我想出的自动解决方案。 I am testing the new What I did is typical, and is roughly as follows, As advertised, the added submodule tracks the master branch of the submodule repo. And I got: In addition, if I do , respectively. However, if I clone the The commands I used to clone and check submodules were: I got: I also tried the same thing happens to In sum, I created a super-project with a submodule tracking its master branch. The branch-tracking capability is lost as soon as I tried to clone it and work on it elsewhere. It seems to me that the only way to keep branch-tracking submodules is to compress the original My question is, how to keep the branch-tracking capability after cloning the super-project. I am particularly interested in making Note: specifying a branch after the branch is lost (e.g. Git submodules: Specify a branch/tag) is not what I am looking for, because the info given in For anyone else with this problem: As the answers have stated, your submodule tracks a commit. This isn't actually an problem, a submodule represents an external dependency at a single point in time (ie, a commit) rather than an active stream of development (a branch). You manually update this dependency at your choosing (and theoretically, are only ever on Master branch) You only really care about your branch when making commits. Committing without being on a branch makes a detached head, and it starts being easy for your team to lose its work. I solved this at our studio by adding a pre-commit hook to reject commits if not on a branch: This hook is committed to the super repo, along with this BAT (yes, I know, sorry) script to install the hooks New clones need to run the script, which is not perfect, but the closest to an automatic solution I could come up with. 这篇关于克隆超级项目后如何保持git子模块分支状态?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! main
项目,那么 common
子模块克隆项目失去On Branch状态。我不能 git pull 或
git push
在 common $ c $如原型
main
项目中的 origin master
来为克隆的项目中的 common
进行推拉工作,但这似乎是打破追踪子模块(子模块add -b)的目的。
cd main
git clone。 ../main2 --recursive
cd ../main2/common
git status
$ b $
#HEAD分离为0259d75
没有提交,工作目录干净
git clone。 ../main3 --recurse-submodules
,以及,
git clone。 ../main4.git --bare
git clone url_to_main4.git - 递归
main3
和 main4
中。总而言之,我创建了一个超级项目,其子模块跟踪其主分支。一旦我试图克隆它并在其他地方工作,分支跟踪功能就会丢失。在我看来,保持分支跟踪子模块的唯一方法是压缩原来的 main
项目并复制它。我在这种情况下是否遗漏了某些东西,或者正在将最初的项目复制到最佳状态?
main4.git
工作,因为它涉及远程服务器上的裸克隆。
git子模块中添加的信息add -b
仍然丢失,我们又回到原点了。
#!/ bin / sh
函数parse_git_branch_check {
if [[$ {branch_name} ==*(从*分离);然后
echo****************** **************************
echo你需要在提交
echo之前在分支上* *******************************************
出口1
else
echo - 你在分支$ branch_name -
exit 0
fi
}
function parse_git_branch {
git分支 - 无色2> / dev / null | sed -e'/ ^ [^ *] / d'
}
branch_name = $(parse_git_branch)
parse_git_branch_check ;
REM - 为所有子模块创建预连接钩子的链接,以防止没有分支的提交
if EXIST .git\hooks\pre-commit(
del .git\hooks\pre-commit
)
mklink / h .git\ hooks\pre-commit pre-commit
FOR / Ftokens = *%% i IN('DIR .git \modules / A:D / b')do(
if EXIST .git\modules\ %% i\hooks\pre-commit(
del .git\modules\ %% i\hooks\pre-commit
)
mklink / h .git \modules \ %% i \ hooks \ pre-commit pre-commit
)
git submodule add -b
feature (after git 1.8.2), which creates sub-module that allegedly tracks a branch rather than a commit. I am using git version 1.8.4.msysgit.0
. The branch-tracking feature for submodules seems to work fine in the original super-project but fails as soon as the super-project is cloned. To be more specific:1. create a git repo (called common): ...
2. create a main project (called main), which uses common as a library/submodule.
mkdir main && cd main
git init
git submodule add -b master url_to_common.git
git commit -m "initial commit"
cd common
git status
# On branch master
nothing to commit, working directory clean
git pull
or git push
, I getAlready up-to-date.
Everything up-to-date
main
project in any way, the common
submodule in the cloned project loses the "On branch" status. And I couldn't git pull
or git push
inside the common
folder as in the prototype main
project. Of course, I can add origin master
to make pull and push work for common
in the cloned project, but this seems to defeat the purpose of having a tracking submodule (submodule add -b).cd main
git clone . ../main2 --recursive
cd ../main2/common
git status
# HEAD detached at 0259d75
nothing to commit, working directory clean
git clone . ../main3 --recurse-submodules
, as well as,git clone . ../main4.git --bare
git clone url_to_main4.git --recursive
main3
and main4
. main
project and copy it around. Did I missing something in this case, or is copying the original project around the best I can have?main4.git
work because it involves a bare clone on a remote server.git submodule add -b
is still lost, and we are back to square one. We might as well delete the submodule and add it again.#!/bin/sh
function parse_git_branch_check {
if [[ ${branch_name} == "* (detached from "* ]]; then
echo "********************************************"
echo "You need to be on a branch before committing"
echo "********************************************"
exit 1
else
echo "-- You are on branch $branch_name --"
exit 0
fi
}
function parse_git_branch {
git branch --no-color 2> /dev/null | sed -e '/^[^*]/d'
}
branch_name=$(parse_git_branch)
parse_git_branch_check;
REM - Create links for all submodules to our pre-commit hooks for preventing submissions without a branch
if EXIST .git\hooks\pre-commit (
del .git\hooks\pre-commit
)
mklink /h .git\hooks\pre-commit pre-commit
FOR /F "tokens=*" %%i IN ('DIR .git\modules /A:D /b') do (
if EXIST .git\modules\%%i\hooks\pre-commit (
del .git\modules\%%i\hooks\pre-commit
)
mklink /h .git\modules\%%i\hooks\pre-commit pre-commit
)