如何查看项目的git历史记录并还原为较早的提交? [英] How to view the git history of a project and revert to an older commit?

查看:329
本文介绍了如何查看项目的git历史记录并还原为较早的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是开源和git的新手.我一直在学习git并为一个项目做贡献.我的任务是在过去的提交中查看它的git历史,然后从代码中学习(因为该项目现在已经发展了). 我知道git存储了项目的整个历史.因此,有没有一种方法可以在本地还原到项目的较旧版本.我无意或无权及时还原其远程存储库,我只想将本地副本恢复为较早的提交.

I am new to open source and git. I have been learning git and contributing to a project. I have been assigned the task of looking into its git history at past commits and learning from the code then (since the project has evolved now). I know that git stores the entire history of the project. So is there a way to revert to an older version of the project locally. I don't intend to or have rights to revert its remote repo back in time, I just want to revert my local copy to an older commit.

推荐答案

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

gitk shows a graphical history of commits, each with a unique SHA hash indentifier.

您可以使用git checkout {commit id}签出到早期版本.您可以使用以下命令将Git恢复为早期版本:

You can checkout to an earlier version using git checkout {commit id}. You make Git revert to an earlier version using these commands:

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

# move the branch pointer back to the previous HEAD
git reset --soft HEAD@{1}

git commit -m "Revert to 56e05fced"

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

还原为Git中SHA哈希的提交?

这篇关于如何查看项目的git历史记录并还原为较早的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆