在git版本2中推送子模块

时间:2016-12-13 14:38:25

标签: git git-submodules git-push

我使用git版本2.7.4和子模块。我的项目结构是这样的:

main/
   file1
   file2
   subm1/
       file3
       file4
   subm2/
       file5

根据this question我想推进子模块。例如,在更改file3之后​​,我使用此命令来推送它:

cd subm1/
git add file3
git commit -m 'Update file3'
git push origin master

我收到了这个错误:

Pushing submodule 'subm1'
To <submodule git repo>
 ! [rejected]        master -> master (non-fast-forward)
error: failed to push some refs to <submodule git repo>
hint: Updates were rejected because a pushed branch tip is behind its remote
hint: counterpart. Check out this branch and integrate the remote changes
hint: (e.g. 'git pull ...') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.
Unable to push submodule 'subm1'
fatal: Failed to push all needed submodules!

但是当我像这样使用拉取了Already up-to-date

subm1$ git pull origin master 
From https://gitlab.com/systemnegar-ai/compare
 * branch            master     -> FETCH_HEAD
Already up-to-date.

如何将其推入子模块原始存储库?

1 个答案:

答案 0 :(得分:1)

我的代码不在master分支中,切换到master分支解决了这个问题。