Git子模块总是检查特定的提交

时间:2014-04-24 16:31:15

标签: git git-submodules

我的一个git子模块总是检查一个特定的提交:

首先,它在主存储库中显示为已修改:

 % git status                                                                                                                                                                                                         
On branch master
Your branch is ahead of 'origin/master' by 3 commits.
  (use "git push" to publish your local commits)

Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        modified:   wp-content/themes/site-wp-theme (new commits)

这是git submodule status

的输出
% git submodule status                                                                                                                                                                                               
+9eb1fbd567d588b44105487d368ff7d12b5fd50b wp-content/themes/site-wp-theme (heads/master)
 15466ab74c20f67ef8ca04e7841d02e85323d36c wp-content/themes/wp-siteny-theme (heads/master)

尝试更新:

% git submodule update                                                                                                                                                                                               
warning: unable to rmdir admin/inc/cmb: Directory not empty
warning: unable to rmdir admin/inc/redux: Directory not empty
Submodule path 'wp-content/themes/site-wp-theme': checked out 'c010f3a0b6e5c4721d8e79d312b1fffa342340b8'

然后我必须转到子模块,然后执行git checkout master来恢复它,这会使其在git status上再次显示为已修改。

这是我的.gitmodules文件:

[submodule "site"]
    path = wp-content/themes/site-wp-theme
    url = https://ajf-@bitbucket.org/ajf-/site-wp-theme.git
    fetchRecurseSubmodules = true
    ignore = untracked
[submodule "siteny"]
    path = wp-content/themes/wp-siteny-theme
    url = https://ajf-@bitbucket.org/ajf-/wp-siteny-theme.git
    fetchRecurseSubmodules = true
    ignore = untracked

我该如何解决这个问题?

2 个答案:

答案 0 :(得分:1)

git submodule update会使父repo更新它注册的SHA1的子模块,而不是你在该子模块中修改的SHA1。

如果父仓库的状态显示子模块的修改后的SHA1,您所要做的就是:

  • 确保您已将子模块推送到其自己的上游bitucket repo
  • 返回到父repo,git add,git commit和git push,以便在代表它的gitlink中注册子模块的新状态(gitlink是special entry, mode 160000)。

答案 1 :(得分:0)

git submodule update检查git认为应该在的提交的所有子模块;它就像子模块的git checkout .

相反,您想通过将该修订提交给父代表来告诉git 9eb1fbd是应该的那个。

这样做:

  • 进入子模块并检查该提交。如果它是你刚刚提交的新提交,请确保将其推送到子模块的上游,以便其他协作者能够将其拉出来。
  • 进入父回购;子模块应标记为具有“新提交”,因为签出的修订版与提交给父代仓库的修订版不同。
  • 直接提交子模块路径,就像它是任何其他文件一样。它可以是其他更改提交的一部分,也可以单独使用。
相关问题