2013-01-08 97 views
2

有没有办法回滚到git(对于整个回购)检查的更早版本?我不想改变回购协议中的内容,我只想要9个月前回购协议的本地副本。Git:回滚到早期版本

回答

2

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

git clone <repo-url> 

...找到犯,分支或标记,你从10个月前要...

git log 
git branch 
git tag 

...和然后结帐旧版本...

git checkout <commit-sha1, branch, tag> 

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

+0

非常感谢您的帮助。这个git仓库没有分支。这只是很多提交...当我这样做:git结帐我收到一个错误“错误:以下untracked工作树文件将被结帐删除:”有没有办法解决这个问题? – Sparky1

+0

@ Sparky1你可以'藏匿'你的改变,将它们提交给一个分支,或者删除它们。 – alex

+0

这是一个新鲜的克隆。自克隆以来我没有做任何改变。你是说我需要隐藏在我想要回滚的提交后的9个月内发生的所有提交? – Sparky1

2

你可以从字面上告诉git在9个月前结帐分支。下面是我的一个项目为例:

:; git checkout '[email protected]{9 months ago}' 
Checking out files: 100% (625/625), done. 
Note: checking out '[email protected]{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都记录方式全部。