繁体   English   中英

子模块中的Git pull将创建另一个子模块

[英]Git pull while in submodule will create another submodule

与子模块打交道时,我对git pull有一个主要问题。 我以为我开始了解他们的原理,但显然不...

我创建了一个简单的git repo Super并在其中创建了一个子module 我的第一个问题是在module提交(添加文本文件)并推送代码时,我可以在github上看到文本文件未进入子module但实际上进入了超级项目Super (子模块)甚至不在github中显示)。 因此,当我在Super执行git pull时,最终会得到已放入子模块中的本地repo文本文件中的文本文件...我不确定自己在做什么错。 这基本上是代码:

   cd module (a text file "Test" was added to be commited)
   ~/Super/module [master]: git add -A
   ~/Super/module [master]: git commit -m 'comment'
   ~/Super/module [master]: git push
   cd Super
   ~/Super [master] : git pull
   and now the text file "Test" shows up in my Super next to the submodule "module".

所以这已经是个问题,但我可以接受。 现在,我进入我的Super并删除此文本文件,然后添加对子模块module所做的更改,以重新指向最新的子模块提交。

(after deleting the text file )
~/Super [master] : git add -A
~/Super [master] : git commit -m 'comment 2'
~/Super [master] : git submodule update
~/Super [master] : git pull
~/Super [master] : git push

我现在进入子模块并进行git pull

~/Super/module [master]: git pull

然后创建超级module中所有东西的副本并将其放入子module 因此,如果我在module执行ls ,我会发现一个嵌套的子module ,这是一个大问题。

~/Super/module/module [master]: 

所以我基本上有两个问题:

  • 当我推送我的子模块时,副本将转到超级项目

  • 在更新超级项目后拉入我的子模块时,它会创建一个嵌套的子模块。

有人可以告诉我我在做什么错吗? 非常抱歉,如果这对您来说似乎很明显,但是我已经在这个问题上停留了一段时间了,这非常令人沮丧。

我从超级添加了.gitmodules文件和.git / config:

.gitmodules:

[submodule "module"]
path = module
url = git@github.com:titocazou/Super.git

.git / config:

[core]
repositoryformatversion = 0
filemode = true
bare = false
logallrefupdates = true
[remote "origin"]
url = git@github.com:titocazou/Super.git
fetch = +refs/heads/*:refs/remotes/origin/*
[branch "master"]
remote = origin
merge = refs/heads/master
[submodule "module"]
url = git@github.com:titocazou/Super.git

在我看来,您可能为子模块设置了错误的远程路径,因此您的子模块实际上指向与您的父存储库共享的远程。 (基本上,您已经在内部复制了存储库。)

检查.gitmodules的内容,以查看子模块实际指向的远程路径以进行推入和拉出,并确保该路径与父存储库要推入和从其拉出的路径不同。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM