5

让我们看看它是什么

  • 创建两个 git repo sub&test
mkdir 测试子
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 ..
  • sub回购移动到test
mv 子测试
光盘测试
git添加子
git commit -m "添加子目录"

我想把它们当作一个 git repo 并远程推送它们,但是现在目录下的文件sub不能被包含?

如何以简单的方式实现这一点,例如将 sub 视为普通目录?

用例

我尝试JENKINS_HOME使用演示将我的 jenkins 数据文件夹 () 添加到 docker 图像中Dockerfile。( ADD JEKINS_HOME /opt/jenkins)

JENKINS_HOME
Dockerfile

我的 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/...(跳过)
./自述文件
4

2 回答 2

2

看来你不能这样做。该名称.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环境变量传递给插件,因此它可以使用另一个名称。

于 2016-06-17T23:06:20.140 回答
0
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 ?

They are not included because test sees repo sub as nested git repo, and records only its gitlink, or SHA1, and not its url as it would have if sub had been added as a submodule.

You would need to push sub to a remote url first, and then add it as submodule for test to see sub files.

 cd test
 git submodule add -- /url/to/sub

Or you would need to use a subtree

cd test
git subtree --prefix sub /url/to/sub master --squash
于 2016-06-18T00:05:07.267 回答