首先想到的是git clone
直接遷出:
$ git clone -b <branch-name> --some-date-related-param <value> repos
但是遺憾的是git clone
沒(méi)有這個(gè)功能镜悉,git clone
只會(huì)遷出所有的代碼庫(kù)內(nèi)容斩启,所有的分支和提交歷史嚎杨。
那么能用的方法就是在git clone
之后使用git checkout
切換到指定時(shí)間點(diǎn)白翻。
例如:
$ git checkout --some-date-related-param <yyyy-mm-dd hh:MM:ss>
還是令人遺憾的,git checkout
并不支持時(shí)間日期作為參數(shù),它只能使用commit作為參數(shù)。
于是剩下的問(wèn)題就是找到那個(gè)時(shí)間點(diǎn)對(duì)應(yīng)的commit了曼玩。
總結(jié)起來(lái)就是分兩步走:
- 第一步:找到時(shí)間點(diǎn)的commit
$ git rev-list -n 1 --first-parent --before="2020-01-10 12:12:00" <branchname>
<commithash>
- 第二步:切換到指定的commit
$ git checkout <commithash>
如何把上述兩步寫(xiě)入一個(gè)命令行就是:
$ git checkout $(git rev-list -n 1 --first-parent --before="2020-01-10 12:12:00" <branchname>)