简体   繁体   中英

How to clone a git repository before a particular date?

I have a dataset from 2014 that includes bug reports and the corresponding fix commit. The commit SHA is seven digits long, and I guess, in 2014, it was sufficient to identify a commit uniquely. However, in 2022 7 digit SHAs can not identify all commits uniquely anymore.

Therefore, I wonder whether I can clone the repository with commits only on or before 2014 so that seven-digit SHA is sufficient to identify all commits uniquely.

If you only want to clone everything before a certain date and from one branch, create a new branch at the last commit to be included either on the server or by pushing a local branch.

After this, clone the repository using the --branch your_created_branch option to checkout the branch that you created and the --single-branch option to clone only the history leading up to the branch that you specified.

Be aware that if you attempt to fetch or pull at any point in the future, you may end up pulling other more recent commits and branches into the local repo.

See documentation for git clone here.

Repository clone will give you whole commit history of that repository. So its not a good idea.

  1. You can type command git log which will show details about all the previous commits
  2. Than you can change state to a specific/desired commit by typing git checkout commit-hash . Commit hash will be unique id of that commit you want to move.
  3. To narrow down list of commit you can also try this command git log --since=2014-05-05 --until=2014-05-06 . This will retrieve result between dates

Besides Jonathon S.'s answer , which is a pretty good way to automate everything given limitations he outlined, note that modern Git will list out all matching objects, given a short hash:

$ git rev-parse a123
error: short SHA1 a123 is ambiguous
hint: The candidates are:
hint:   a1231de002 commit 2011-01-26 - tests: sanitize more git environment variables
hint:   a123978771 commit 2009-04-23 - git-show-branch.txt: cleanup example description
hint:   a123a47f40 commit 2018-08-28 - l10n: ru.po: update Russian translation
hint:   a123b19eec commit 2015-08-24 - Merge 'kn/for-each-tag-branch' into kn/for-each-tag
hint:   a12303cc5e tree
hint:   a123f8cce3 tree
hint:   a1230d7ead blob
a123
fatal: ambiguous argument 'a123': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

(I ran this in a clone of the Git repository for Git itself), or:

$ git rev-parse a123^{commit}
error: short SHA1 a123 is ambiguous
hint: The candidates are:
hint:   a1231de002 commit 2011-01-26 - tests: sanitize more git environment variables
hint:   a123978771 commit 2009-04-23 - git-show-branch.txt: cleanup example description
hint:   a123a47f40 commit 2018-08-28 - l10n: ru.po: update Russian translation
hint:   a123b19eec commit 2015-08-24 - Merge 'kn/for-each-tag-branch' into kn/for-each-tag
a123^{commit}
fatal: ambiguous argument 'a123^{commit}': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'

If you don't need automatic resolution, you can let git rev-parse spit out all the possibilities and pick out the one(s) you think are right. Add the ^{commit} limiter to reduce the number of matches if you like.

(Note that the ones that are commit are followed by the commit date and short subject line, which makes your task that much easier.)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM