Git:回到早期版本

时间:2013-01-08 00:07:16

标签: git

有没有办法可以回滚到早期版本的git(对于整个仓库)?我不想改变回购中的内容,我只想要9个月前回购地点的本地副本。

2 个答案:

答案 0 :(得分:2)

是的,只需克隆回购......

git clone <repo-url>

...从9个月前找到你想要的提交,分支或标签......

git log
git branch
git tag

...然后查看旧版本......

git checkout <commit-sha1, branch, tag>

请记住,如果您签出提交,您将处于分离的HEAD模式。如果您希望进一步提交,可以为该提交创建分支。

答案 1 :(得分:2)

从9个月前开始,你可以告诉git结帐分支。以下是我的一个项目的例子:

:; git checkout 'master@{9 months ago}'
Checking out files: 100% (625/625), done.
Note: checking out 'master@{9 months ago}'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:

  git checkout -b new_branch_name

HEAD is now at b50869f... ignore DerivedData

指定修订的所有方法都记录在the git-rev-parse man page