2016-04-29 82 views
0

TLDR:我可以检查分支库是否是git子模块的分支?现在它似乎只是检查父回购的分支机构,即使它与我最近提交的所有分叉回购的头部分离。子模块分拣版本库获取父版本库的分支


有一个开放源码库,我不管理称为TheLibrary我添加的git的子模块。然后我需要修改库并将其用作git子模块,所以我在github上分叉它,添加了一个新分支modifications并在那里进行修改。然后,我更新了我的项目的.gitmodules文件包含我的分叉图书馆的网址,像这样:

[submodule "libs/TheLibrary"] 
    path = libs/TheLibrary 
    url = https://github.com/myUsername/TheLibrary.git 
    branch = modifications 

然后我做了在终端git submodule sync,这给了这样的结果:

Synchronizing submodule url for 'libs/TheLibrary' 

然后我就去到libs/TheLibrary目录在终端上,当我做了git fetch它给了我从父回购(主,功能/ FeatureA)的分支。但是,我的分叉存储库应该只有这些分支:(主,修改)。

当我做git remote -v,它给了这样的结果:

origin https://github.com/myUsername/TheLibrary.git (fetch) 
origin https://github.com/myUsername/TheLibrary.git (push) 

当我做git branch,它有这个:

* (HEAD detached at a1b2c3def) 
feature/featureA 
master 

但是,功能/ featureA只是一个拉请求我做了父库。我分叉的存储库应该有我添加的modifications分支。

当我做git log时,它显示了所有最近从modifications分支提交的提交。

如何查看modifications分支,以便我可以继续将更改添加到分叉库中,并将它们推送到远程回购?目的是希望它仍能够将来自父回购的更新合并到我们自己的更改中。这甚至可能吗?谢谢!

回答

0

TLDR:我无法更新现有模块以使其工作。我不得不与-b标志运行此命令,它的工作: git submodule add -b modifications https://github.com/myUsername/TheLibrary.git

因此,修改现有的子模块手动似乎没有工作,甚至当我删除整个库文件夹(libs/TheLibrary),并回顾git submodule initgit submodule update(重新克隆它)。

但是,当我这样做:

git submodule add -b modifications https://github.com/myUsername/TheLibrary.git

它把它在当前文件夹中的错误(我想我应该把正确的路径作为最后一个参数),但是当我在那里去了看它是否检查了右支(我做git status)它说:

On branch modifications 
Your branch is up-to-date with 'origin/modifications'. 
nothing to commit, working directory clean 

这意味着它的工作!良好的措施,我确实git branch,看它是否有正确的分支:

master 
* modifications 

,它做到了!所以我认为它总是需要以这种方式完成,使用带有-b标志的命令,而不是我尝试手动更新子模块的方式。


注意:它的工作即使之后,加入这.gitmodules

[submodule "TheLibrary"] 
     path = TheLibrary 
     url = https://github.com/TheLibrary/TheLibrary.git 
     branch = modifications 

即使它是完全一样的东西我以前(除了不同的路径)中输入相同,它以前没有工作。运行命令时可能会出现其他一些幕后的事情,我想手动修改这些文件是不够的。


注2:当我终于得到了正确的文件夹中,我得到这个混帐错误:

A git directory for 'libs/TheLibrary' is found locally with remote(s): 
    origin https://github.com/myUsername/TheLibrary.git 
If you want to reuse this local git directory instead of cloning again from 
    https://github.com/myUsername/TheLibrary.git 
use the '--force' option. If the local git directory is not the correct repo 
or you are unsure what this means choose another name with the '--name' option. 

所以我跑这个命令与--force选项,并验证了它的工作:

git submodule add --force -b modifications https://github.com/myUsername/TheLibrary.git