如何将git子模块作为普通目录添加到git repo中? [英] how can I add git submodule into git repo as normal directory?
问题描述
让我们看看它是什么
- 创建两个git仓库
code>&
test
mkdir test sub
cd test && git init && touch README && git add README && git commit -m初始化git repo&& cd ..
cd sub && git init && touch README && git add README && git commit -m初始化sub git repo&& cd ..
- 移动
sub
回购进入
测试
mv sub test
cd test
git add sub
git commit -madd sub directory
我想将它们视为一个git仓库,并将它们远程推送,但现在 sub
目录下的文件不能包含在内?
我如何以简单的方式实现此目标,比如将sub作为普通目录?
用例
我尝试使用 Dockerfile $>将我的jenkins数据文件夹(
JENKINS_HOME
)添加到docker映像中c $ c>用于演示。 ( ADD JEKINS_HOME / opt / jenkins
)
JENKINS_HOME
Dockerfile
我的jenkin的 scriptler插件,其中包含git回购。然后,它存在于我的docker image git repo中,如下所示:
$ find jenkins-docker
./.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 / ...(跳过)
./README
似乎你做不到在源代码中, .git
这个名称是硬编码的: https://github.com/git/git/blob/fe9122a35213827348c521a16ffd0cf2652c4ac5/dir.c#L1260
可能有一种方法是创建一个脚本,将 .git
重命名为其他内容,并在将它添加到repo之前和之后返回
在 s下的工作目录中cripts
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屋!