سؤال

One of my git submodules is always checking out a particular commit:

First, it appears modified in the main repository:

 % 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)

This is the output of git submodule status

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

Trying to update:

% 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'

So then I have to go to the submodule, and do git checkout master to restore it, which makes it show up again on git status as modified.

This is my .gitmodules file:

[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

How can I solve this?

هل كانت مفيدة؟

المحلول

git submodule update would make the parent repo update the submodule at the SHA1 it registered, not at the modified SHA1 you made in that submodule.

If the status of the parent repo shows you a modified SHA1 for a submodule, all you have to do is:

  • make sure that you have pushed the submodule to its own upstream bitucket repo
  • go back to the parent repo, git add, git commit and git push, in order to register the new state of the submodule in the gitlink which represents it (the gitlink is the special entry, mode 160000).

نصائح أخرى

git submodule update checks out all the submodules to the commits that git thinks they should be at; it's like the git checkout . of submodules.

Instead, you want to tell git that that 9eb1fbd is the one it should be, by committing that revision to the parent repo.

To do so:

  • Go into the submodule and check out that commit. If it's a new commit you've just made, ensure it's pushed to the upstream for the submodule, so other collaborators will be able to pull it.
  • Go into the parent repo; the submodule should be marked as having "new commits" because the checked out revision differs from the one committed to the parent repo.
  • Commit the submodule path directly, just as if it were any other file. It can be part of a commit with other changes, or just on its own.
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top