Home > Software design >  How to clone a git repository before a particular date?
How to clone a git repository before a particular date?

Time:02-23

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.

CodePudding user response:

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.

CodePudding user response:

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
  •  Tags:  
  • git
  • Related