Our team is using git submodules, but we run into some errors with pulling, which tells us that we are behind even though we recently updated (and there have been no remote commits / pushes since). This happens in two scenarios:
- with detached
HEAD
in our submodules, or - when using
git commit --amend
.
I will try and show the scenarios where these things have happened. My question is, does anyone know where the specific error lies, and a simple method (better than our dirty hacks) to fix them?
Scenario 1 - Detached HEAD
- We issue either:
git clone --recursive $REPO $DIR
git sfe 'git pull origin master'
git submodule update --recursive
- We have actually not used this much because it tends to put us in detachedHEAD
state
- We check to see if all branches are on
master
(or at least not in detachedHEAD
state) withgit sfe 'git branch'
. If not, we issue agit sfe 'git checkout master'
. (We are currently all (~4 people) developing on master, just to minimize having to merge and for getting up and running) - If we are in detached
HEAD
, make changes, then later switch tomaster
(so our unstaged files stay in the working directory), stage and commit those changes, then try to push, Git says that we must pull because we are behind. We can fix this by:- Saying 'screw it', checking out an entirely clean supermodule, make sure that we are not in detached
HEAD
, and work from there - Get the revision number,
git checkout master
, then issue agit merge $REV
and go through the pain of re-merging current changes the conflict with the past changes that seem to be in there.
- Saying 'screw it', checking out an entirely clean supermodule, make sure that we are not in detached
Scenario 2 - Amending a Commit
- Not much to this one. I will be developing on my own, issue a
git commit --amend
, then try to push those changes. However, when I do this, it tells me that I am behind and must merge. When I do, it is once again the painful process of re-merging all of the current changes with past revisions.- Is this because I am trying to push something that is based on a commit that is no longer the
HEAD
?
- Is this because I am trying to push something that is based on a commit that is no longer the
Note: git sfe
is our alias for git submodule foreach --recursive
(we have some nested submodules, just for masochism [or rather, the fact that we need to be able to separate the code out and the placement for the sub-submodule makes sense])