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