Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/10.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Git 更改现有子模块';s分支_Git_Git Submodules - Fatal编程技术网

Git 更改现有子模块';s分支

Git 更改现有子模块';s分支,git,git-submodules,Git,Git Submodules,最初添加子模块时,我指定了一个特定的分支,如.gitmodule文件所示: [submodule "externals/grpc/grpc"] path = externals/grpc/grpc url = git@github.com:me/grpc.git branch = release-1.0 我想更改为子模块的主分支,因此我将.gitmodules中的分支从release-1.0更改为master,为了更好地衡量,我刚刚从父git树中删除了子模块: cd $

最初添加子模块时,我指定了一个特定的分支,如
.gitmodule
文件所示:

[submodule "externals/grpc/grpc"]
    path = externals/grpc/grpc
    url = git@github.com:me/grpc.git
    branch = release-1.0
我想更改为子模块的主分支,因此我将
.gitmodules
中的分支从
release-1.0
更改为
master
,为了更好地衡量,我刚刚从父git树中删除了子模块:

cd $submodules
rm -rf grpc
cd $gitroot
git submodule sync
git submodule update --init --recursive
现在,当我回到我的子模块时,它仍然是从
release-1.0
分支上的提交中签出的,而不是最新的主提交


切换子模块的分支时,我遗漏了哪些步骤?

进入子模块所在的目录,并
git checkout
正确的分支/提交。然后上升一级,然后
git添加
git提交
目录。这将使用正确的提交签入子模块

不要忘了在其他客户机上运行
git submodule update--recursive

上面的答案(@milgner)对我不起作用(git版本2.17.0)。也许我做错了什么

以下是对我有效的方法:

nano .gitmodules # substitute the needed branch here
git submodule update submodule_name # update the submodule
git add .gitmodules && git commit -m 'some comment' # add and commit
git submodule status # check that changes have been applied

如果您想切换到以前从未跟踪过的分支机构。

.gitmodules
中更改分支后,请执行以下操作:

git submodule update --init --recursive --remote
cd submodule_name
git checkout new_branch_name