2

Partly as an exercise, partly because it almost works and I feel the need to finish it...

I can git clone $repo --branch $ref --single-branch --depth 1 and it works great for tags and heads.

I can git pull --depth 1 $repo $sha and it works great, as long as $sha is a FULL value. BUT: this fails if that is abbreviated, even by 1 character.

Is there any way achieve this? I am trying to automate git synchronization and very large repos are a problem. Using depth 1 helps a ton, but I can't figure how to use an abbreviated SHA.

Tim Hockin
  • 3,567
  • 13
  • 18
  • What is the error? – Mad Physicist Dec 13 '19 at 05:12
  • `fatal: couldn't find remote ref 9f145865e04`. But if I use a full SHA I get ` * branch 9f145865e04e50836bdaaf0431485346d82f8792 -> FETCH_HEAD` – Tim Hockin Dec 13 '19 at 05:16
  • You cannot use an abbreviated hash. You can only use a hash at all if the other Git is configured to let you do that (apparently this one is). – torek Dec 13 '19 at 05:50
  • BTW this is really the same question as [Git clone --single-branch does not work for sha / commit ids?](https://stackoverflow.com/q/57316783/1256452) but there is no accepted answer there. – torek Dec 13 '19 at 07:48

1 Answers1

1

I just tried using the git -c core.abbrev=40 option, as shown in "Making git output full (un-abbreviated) hashes for all commands?"

git -c core.abbrev=40 --branch 05f7b9c710 --single-branch --depth 1 https://github.com/auser/arepo test

But that still fails with:

Cloning into '`test`'...
warning: Could not find remote branch 05f7b9c710 to clone.
fatal: Remote branch 05f7b9c710 not found in upstream origin

As explained in "git clone --single-branch does not work for sha / commit ids?"

This was intentional, to allow some control over what could be fetched from repos, especially in setups where a single object db serves multiple repos.

By the way, uploadpack.allowAnySHA1InWant is not set on GitHub side.
That means even if I were to use a full SHA1 reference, it would still fail.

In your case, if you have control over the Git remote repository hosting server, you might set the setting to allow such a clone.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250