During a fetch, the server can list references that it has and that the client may wish to fetch. These are the advertised references.
- It looks like you cannot directly get any single specific commit from the server, only refs (i.e. branches and tags). Or rather, that Github servers are configured to disallow such requests.
So, if you want to get a specific commit with
--depth, it must be at most
<depth>-1commits away from the fetched ref (which is the branch/tag specified in the submodule’s metadata)
Typically, folks advise to just set
depthto some number reasonably large but still much smaller than the total number of commit in the repo — like
50is what Travis uses when doing the initial clone for the project.
If you aren’t updating the submodule with
--depth, failing to find the commit would mean any of:
- the submodule’s tree is in “shallow” state and the above applies (only possible when it was previously updated with
--depthor its entry in
shallow = true)
- the commit is not on the branch that the submodule is using
- the commit is not in the submodule’s repo at all:
- either someone made a mistake,
- or it was once there but was deleted by a forced push
For the record, in your specific case, it was the last case: commit
5bbcdc5df9d01b521e8da011bab0da70bdec3653 is not in the
https://github.com/simsong/http-parser.git repo at all.
One way to get access to an unadvertized object is to sync. Then a submodule update should work, like:
git submodule sync --recursive git submodule update
This can happen when you are pointing to submodule commit that has been removed through a history re-write or squash. The best you can do is:
- First get a clear picture of what your team has been doing so you know what it should look like.
- Update your local with a git pull and then find the closest commit that works with your branch (it may be the latest) and then add that to your parent repo. e.g. something like:
parent-repo$ git fetch parent-repo$ cd submodule-a submodule-a$ git pull submodule-a$ git checkout best-commit-according-to-team-and-your-branch submodule-a$ cd ../ parent-repo$ git status ... Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) (commit or discard the untracked or modified content in submodules) modified: submodule-a (modified content) ... git add submodule-a git commit -m "updated submodule-a reference"
Once you are happy it is correct and your team agrees you can push it up and the error should go away.
When I run:
git submodule update
git submodule update --init --recursive
I got the error:
error: Server does not allow request for unadvertised object xxxxxxxxx
Fetched in submodule path ‘xxx’, but it did not contain
xxxxxxxxx.Direct fetching of that commit failed.
And I fixed this problem by :
git submodule update --remote
For me, this tends to happen when I push a parent git repo back to github without pushing back a sub-module that I’ve modified and committed, but haven’t pushed back.