首先想到的是git clone
直接迁出:
$ git clone -b <branch-name> --some-date-related-param <value> repos
但是遗憾的是git clone
没有这个功能,git clone
只会迁出所有的代码库内容,所有的分支和提交历史。
那么能用的方法就是在git clone
之后使用git checkout
切换到指定时间点。
例如:
$ git checkout --some-date-related-param <yyyy-mm-dd hh:MM:ss>
还是令人遗憾的,git checkout
并不支持时间日期作为参数,它只能使用commit作为参数。
于是剩下的问题就是找到那个时间点对应的commit了。
总结起来就是分两步走:
- 第一步:找到时间点的commit
$ git rev-list -n 1 --first-parent --before="2020-01-10 12:12:00" <branchname>
<commithash>
- 第二步:切换到指定的commit
$ git checkout <commithash>
如何把上述两步写入一个命令行就是:
$ git checkout $(git rev-list -n 1 --first-parent --before="2020-01-10 12:12:00" <branchname>)