GitHub - Repository state at specified time

蹲街弑〆低调 提交于 2021-02-19 01:16:17

问题


I am beginner in using git versioning tool.

I would like to download repository state (files) at specified time (e.g. on 5.10.2013). How can I do that ?


回答1:


Click "Commits" and look for a commit that was on that date. Now clone the repository to your computer and check out that commit.




回答2:


As of May 2019 (not sure when this was introduced), you can simply add the date in the following format - HEAD@{2019-04-29} - in the place of the URL where the commit would usually belong.

Example: Here is a link to the react repo on a recent commit https://github.com/facebook/react/tree/95e06ac3d091b6746be80d13840884dc7894b01c

Replacing the commit hash with the date formatted as above https://github.com/facebook/react/tree/HEAD@{2019-04-29} will bring you to the React repo as it looked on April 29.

You can also compare commits based on time - see more info from Github's help docs here: https://help.github.com/en/articles/comparing-commits-across-time#comparisons-across-time




回答3:


Use the rev-list command to search for commits it revers chronological order

git rev-list <branch-name> --max-count=1 --before=<timestamp>

For a concrete example. The commit before Jan 10 2014 on my master branch

git rev-list master --max-count=1 --before=2014-10-01



回答4:


First, I would very much recommend that you avoid using a date. This is a very inexact way of looking at a repository at a certain point in time. Instead, be exact, and pick a specific commit or tag. Typically people want to revert back to a particular release, in which case there should be a tag. You can list all available tags by typing git tag.

If you'd rather use a commit then use git log to find the commit. This command supports a lot of options which you can view by typing git help log. For example, on the o-js repo on GitHub git log --oneline produces:

10b5421 Add .npmignore to bower.json ignore list.
a7681b2 Update package.json for new CommonJS structure and add an .npmignore.
c9e3a52 Migrated everything to CommonJS format modules (no more hacks for the we
9af7a3d Lots of adjustments to reduce the minified size by several kilobytes.
c1c7bda Better error messaging across the board (no more "..." errors). Fixes #4
008871d Adjust exception throwing a bit to be more minification-friendly.
3bce458 Expose o.ucFirst to the public.
866d53e Added o.positiveIntType due to this type being a common case.
cc395d1 New CHANGES file format.
f26de19 Massage the CHANGES list a bit for the next release.

The hashes are actually 40 characters long, but --oneline just includes the first 7 characters, as do many other commands. You can use the 40-character version or the 7-character version of the hash.

If you'd like to list commits around a certain date you can do:

git log --oneline --since=2013-05-05 --until=2013-05-15

You asked about being able to download the files. This makes me think that you do not want to clone the repository, and instead just want a full snapshot in time of the repository at a certain point (without the .git directory). This is done using the git archive command which takes a tree-ish value for the point in time. Tags and commits work fine for this.

If you wanted a tar archive of the o-js repo for release v0.0.6 you'd do:

git archive --output=o-js-0.0.6.tar v0.0.6

This creates o-js-0.0.6.tar in the current directory with all files at the state they were in when the v0.0.6 tag was created. Again, you can replace v0.0.6 in the command with a commit hash and it will work just as well.

If you did not actually want just the files and instead wanted to rewind your git checkout to a point in time you'd do this instead:

git reset --hard v0.0.6

The git reset command is dangerous in inexperienced hands, so use it with caution. This documentation about git reset is a great start:

http://git-scm.com/blog/2011/07/11/reset.html



来源:https://stackoverflow.com/questions/21345787/github-repository-state-at-specified-time

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!