如何将 git 子模块作为普通目录添加到 git repo 中? [英] how can I add git submodule into git repo as normal directory?
问题描述
让我们看看它是什么
- 创建两个git repo
sub
&测试
- 将
sub
存储库移动到test
我想把它们当成一个git repo远程推送,但是现在sub
目录下的文件不能包含了?
如何以简单的方式实现这一点,例如将 sub 视为普通目录?
用例
我尝试使用 Dockerfile
将我的 jenkins 数据文件夹 (JENKINS_HOME
) 添加到 docker 映像中以进行演示.(添加 JEKINS_HOME/opt/jenkins
)
JENKINS_HOMEDockerfile
我的 jenkin 有 scriptler 插件,其中包含其 git repo目的.然后它存在于我的 docker image git repo 中,如下所示
<上一页>$ 找到詹金斯码头工人./.git./.git/..(跳过./Dockerfile./JENKINS_HOME./JENKINS_HOME/scriptler./JENKINS_HOME/scriptler/scripts./JENKINS_HOME/scriptler/scripts/.git./JENKINS_HOME/scriptler/scripts/.git/...(跳过)./JENKINS_HOME/scriptler/scripts/Sample.groovy./JENKINS_HOME/...(跳过)./自述文件看来你做不到.名称 .git
在源代码中是硬编码的:https://github.com/git/git/blob/fe9122a35213827348c521a16ffd0cf2652c4ac5/dir.c#L1260
可能的一种方法是制作一个脚本,将 .git
重命名为其他内容,然后在将其添加到 repo 之前和之后返回
在scripts
下的工作目录
mv .git hidden-git
在 Dockerfile 中
RUN mv $JENKINS_HOME/scriptler/scripts/hidden-git$JENKINS_HOME/scriptler/scripts/.git
另外,也许可以将 GIT_DIR
环境变量传递给插件,因此它可以使用另一个名称.
Let's see what it is
- Create two git repo
sub
&test
mkdir test sub cd test && git init && touch README && git add README && git commit -m "initialize the git repo" && cd .. cd sub && git init && touch README && git add README && git commit -m "initialize the sub git repo" && cd ..
- Move the
sub
repo intotest
mv sub test cd test git add sub git commit -m "add sub directory"
I want to treat them as one git repo and push them remotely, but now the files under sub
directory can not be included ?
How can I achieve this in simple way like treat sub as normal directory ?
Use case for this
I try to add my jenkins data folder (JENKINS_HOME
) into docker images using Dockerfile
for demo. (ADD JEKINS_HOME /opt/jenkins
)
JENKINS_HOME
Dockerfile
My jenkin has scriptler plugin which contains the git repo for its purpose. Then it exists in my docker image git repo like below
$ find jenkins-docker ./.git ./.git/.. (skipped ./Dockerfile ./JENKINS_HOME ./JENKINS_HOME/scriptler ./JENKINS_HOME/scriptler/scripts ./JENKINS_HOME/scriptler/scripts/.git ./JENKINS_HOME/scriptler/scripts/.git/... (skipped) ./JENKINS_HOME/scriptler/scripts/Sample.groovy ./JENKINS_HOME/... (skipped) ./README
Seems you cannot do that. The name .git
is hard-coded in the source code: https://github.com/git/git/blob/fe9122a35213827348c521a16ffd0cf2652c4ac5/dir.c#L1260
Probably one way is to make a script which renames .git
to something else and back before and after adding it into repo like
In working directory under scripts
mv .git hidden-git
In Dockerfile
RUN mv $JENKINS_HOME/scriptler/scripts/hidden-git
$JENKINS_HOME/scriptler/scripts/.git
Alternatively, probably it's possible to pass GIT_DIR
environment variable into the plugin, so it could use another name.
这篇关于如何将 git 子模块作为普通目录添加到 git repo 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!