7

I'd like to clone a repository with a longish history. I'm only interested in a few short-lived not-yet-merged feature branches and master.

In order to not confuse myself with all that past history and merged branches, I'd like to do a shallow clone starting at a specific commit SHA.

However, so far I've only found documentation on how to do shallow clones that only include the last n commits (--depth) resp, the commits since a specific date (--shallow-since).

Is there a way to specify a shallow-clone starting at a given commit?

umläute
  • 28,885
  • 9
  • 68
  • 122

3 Answers3

5

There is not, which is kind of a shame since it would be easy for Git to implement.

Usually using --depth is sufficient: just start with a depth you think is enough, and if it's not, repeatedly fetch with --deepen or --depth as needed.

torek
  • 448,244
  • 59
  • 642
  • 775
0

Still not possible yet, but if we know the datetime of the commit we want to create shallow clone of, we can use git --shallow-since=<date>, example if we know commit X was pushed at "2021-12-19T20:37:05Z", we can:

git clone --shallow-since="2021-12-19T20:37:05Z" <url>

will only give history from commit X

zenoh
  • 2,071
  • 1
  • 22
  • 38
-3

What about creating a branch at that special commit and then git clone --single-branch?

tymtam
  • 31,798
  • 8
  • 86
  • 126
  • 1
    i think that's the wrong way around: i want my history to *start* at the given commit, not to end. – umläute Sep 03 '18 at 09:06
  • yes. i also want all the branches (i'm interested in) that forked off after `xxx`. – umläute Sep 04 '18 at 07:41
  • Oh, OK, I re-read you question and you state explicitly you want "ot-yet-merged feature branches and master". Point taken. – tymtam Sep 04 '18 at 08:43