2012-03-21 97 views
1

我是新来的开源和git。我一直在学习git并为项目做出贡献。我已经被赋予了在过去的提交中研究它的git历史的任务,然后从代码中学习(因为该项目现在已经发展)。 我知道git存储了项目的整个历史。那么有没有办法在本地恢复到旧版本的项目。我不打算或有权及时恢复其远程回购,我只想将本地副本恢复到较旧的提交。如何查看项目的git历史并恢复到较旧的提交?

+0

恢复或只是结账? – 2012-03-21 16:40:11

回答

4

gitk显示提交的图形历史记录,每个提交都有一个唯一的SHA哈希标识符。

您可以使用git checkout {commit id}签出更早的版本。你让Git的恢复使用这些命令的早期版本:

# reset the index to the desired tree 
git reset 56e05fced 

# move the branch pointer back to the previous HEAD 
git reset --soft [email protected]{1} 

git commit -m "Revert to 56e05fced" 

# Update working copy to reflect the new commit 
git reset --hard 

Revert to a commit by a SHA hash in Git?

+0

'git log'或'git log --graph'也会显示提交历史记录。 – 2012-03-21 13:41:51

0

听起来像是你应该使用“混帐重置”,而不是“混帐复归”删除最近的变化和重置前提交。

到列表上提交你可以使用 git的日志 commit ss

那么一旦你已经找到了承诺要恢复,使用第9个 字符,在git的复位CMD喜欢承诺SHA: git reset --hard fbcc6aa00