Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to do a shallow git clone based on datetime?

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.

like image 507
tom Avatar asked May 21 '12 23:05

tom


1 Answers

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).

like image 107
VonC Avatar answered Oct 19 '22 17:10

VonC