21

I wanted to pull commit "3a2ceef391af73994dfeb0d8ef57ed6a52ef4238" from branch android. I used the command:

$ git fetch origin 3a2ceef391af73994dfeb0d8ef57ed6a52ef4238

and it is showing this error,

error: Server does not allow request for unadvertised object 3a2ceef391af73994dfeb0d8ef57ed6a52ef4238

How to solve this problem?

Tazwar Utshas
  • 921
  • 2
  • 17
  • 30

13 Answers13

18

git submodule sync as pointed in https://github.com/AppImage/AppImageKit/issues/511 works for me.

Sravya
  • 661
  • 8
  • 9
12

According to this answer and the given source it looks like BitBucket does not allow you to fetch a commit id, only references.

I cannot say if you can configure this behavior, but I think you can:

  1. Pull the branch: git pull origin branchname
  2. Checkout the local commit id: git checkout <commitid>
Arount
  • 9,853
  • 1
  • 30
  • 43
6

I got the same error and none of these resolved it. It turned out that I hadn't pushed submodule changes from my other computer (this would give 404 error when you click on submodule folder on GitHub). So pushing submodule, committing parent and pushing that as well resolved the error.

Other solutions are git submodule update --recursive and this.

Shital Shah
  • 63,284
  • 17
  • 238
  • 185
5

I got the same error when use git submodule update --init,quickly fix it by using git submodule update --force --recursive --init --remote

JiajiaGu
  • 1,279
  • 14
  • 10
3

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.

pdcoxhead
  • 383
  • 5
  • 11
3

use fetch option --no-recurse-submodules

examples:

    git fetch -q origin refs/tags/*:refs/tags/* --no-recurse-submodules
    git fetch --no-recurse-submodules --no-tags origin 
    git fetch --no-recurse-submodules origin $GERRIT_BRANCH 


While this example is not explicitly stating the commit, I see this error occasionally when doing a git fetch on a repo containing submodules where the submodule contains a commit that is unadvertised.


The error:
"Server does not allow request for unadvertised object 5665ef0fb603a7d1e5a402763c0f2f049623012a"
can be traced back to the git version.
I first saw this error on upgrade to git version 2.22.0. When I rolled the version back to 2.20.0, no error.
Rolling back the git version could also be used as a temporary workaround if you are looking for a quick solution.

GSBran
  • 61
  • 4
2

When I run:

git submodule update

or

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
hxysayhi
  • 1,888
  • 18
  • 25
1

I was facing such an error while doing a git pull. Doing below helped fix the issue for me.

git remote prune origin
git pull
notytony
  • 1,032
  • 2
  • 11
  • 13
1

I got the same problem and unsuccessfully tried some of the above solutions. What worked for me is:

git fetch --unshallow && git fetch origin && git reset --hard origin/master
1

The fact that there are so many different answers where some work and most of them don't is really showing that Git is not stable and too complex for such an easy task. I wonder if the Git architects are able to read this without any embarressment.

Having said that, the following worked for me:

git clone --recurse-submodules git@bitbucket.org:company/mytoprepo.git .

The above does give the error "Server does not allow request for unadvertised object", but just ignore that.

Then do the following:

cd submoduleDirectory
git fetch origin
git reset --hard origin/master

The last command finally gets all the files of the submodule.

Please let me know when this does not work for you. It might be good to increase the embarressment for the Git Architects. Maybe they start making the Git utility more Simple. (That's a concept you don't hear often in IT nowadays: Making stuff Simpler...) :-)

BertC
  • 2,243
  • 26
  • 33
1

This can also happen if you squash commits when you merge a pull request. The id of the commit that is referenced by the parent can be removed during a squash. Be sure to do a regular merge of your pull request if the commit id needs to be retained.

knsheely
  • 543
  • 5
  • 13
1

This can happen simply if the commit hash/id you are trying to checkout does not exist in the repository. For example if you accidentally are in the wrong folder (git repo) when you paste the hash as part of the git checkout command.

JoeAC
  • 852
  • 1
  • 8
  • 13
0

You can follow the below steps to solve the above error .

> git init 
> git pull <reponame> branchname(optional) 
> git reset --hard <commit_id>

Note:make sure that You have committed and pushed your changes from local to remote already as reset --hard will leave any unsaved changes from local and it moves completely and get the files and folders of the commit which is irreversible with any changes not pushed. You may have a look in to these as well.

https://www.pylabz.com/2019/08/using-python-to-pull-files-of-git-hub.html#more

https://medium.com/@deepakr6242/using-python-to-extract-files-from-git-hub-repo-through-commits-id-2bdf76b2e0fd