8

I know I can do a shallow clone by specifying the --depth flag. However, this takes in an integer as its value. Is there any way to have the identical behavior with a datetime? I do not wish to clone the entire repository and checkout a previous state.

George Kagan
  • 5,207
  • 8
  • 44
  • 49
tom
  • 2,115
  • 1
  • 14
  • 29
  • It's already discussed [here][1]. Did you go through it? [1]: http://stackoverflow.com/questions/3790671/how-to-in-git-clone-a-remote-github-repository-from-a-specifed-date – positron May 22 '12 at 04:17
  • Yes, but it involved having the repository cloned already. The reason is that I''m building a script that does not require the entire history of the repository. The cloning is the actual bottleneck in terms of runtime right now. – tom May 22 '12 at 16:44
  • The only idea that comes to my mind is "get the depth by grep-ping the logs corresponding to the date" and specify it. – positron May 23 '12 at 05:49

1 Answers1

7

Why yes it is. At least only with Git 2.11 (Q4 2016)

See commit cccf74e, commit 079aa97, commit 2997178, commit cdc3727, commit 859e5df, commit a45a260, commit 269a7a8, commit 41da711, commit 6d43a0c, commit 994c2aa, commit 508ea88, commit 569e554, commit 3d9ff4d, commit 79891cb, commit 1dd73e2, commit 0d789a5, commit 45a3e52, commit 3f0f662, commit 7fcbd37, commit 6e414e3 (12 Jun 2016) by Nguyễn Thái Ngọc Duy (pclouds).
Helped-by: Duy Nguyen (pclouds), Eric Sunshine (sunshineco), and Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit a460ea4, 10 Oct 2016)

git clone now includes:

--shallow-since=<date>:

Create a shallow clone with a history after the specified time.

The date format should be one of the formats presented in git log.
Although the tests show raw dates:

cd shallow-since &&
GIT_COMMITTER_DATE="100000000 +0700" git commit --allow-empty -m one &&
GIT_COMMITTER_DATE="200000000 +0700" git commit --allow-empty -m two &&
GIT_COMMITTER_DATE="300000000 +0700" git commit --allow-empty -m three &&
git clone --shallow-since "300000000 +0700" "file://$(pwd)/." ../shallow11 &&
git -C ../shallow11 log --pretty=tformat:%s HEAD >actual &&
echo three >expected &&
test_cmp expected actual

"raw date" means: date as seconds since the epoch (1970-01-01 00:00:00 UTC), followed by a space, and then the timezone as an offset from UTC (a + or - with four digits; the first two are hours, and the second two are minutes).

imme
  • 523
  • 1
  • 9
  • 20
VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
  • what's the right way to interpret `"100000000 +0700"`? 100000000 is `1973-03-03 09:46:40`, does the string mean `1973-03-03 09:46:40` at +0700, which is equivalent to `1973-03-03 02:46:40` at UTC? – zyxue Jan 27 '21 at 16:44
  • 1
    @zyxue Yes, it is a Unix timestamp (https://www.silisoftware.com/tools/date.php?inputdate=100000000+%2B0700&inputformat=unix). The idea is to quickly create 3 commits, from oldest to newest, and 100M, 200M, 300M is an easy way to ensure that oldest-to-newest list of commit dates. – VonC Jan 27 '21 at 16:55