简体   繁体   English

如何还原到较早的提交

[英]How to revert to an earlier commit

Total noob question but I've tried the stuff I've seen online to no avail. 总的菜鸟问题,但我尝试了我在网上看到的东西,但没有成功。 I want to make my current head point to an earlier commit. 我想将我的当前要点指向更早的提交。 So I look at my git log, find the commit I like, and then type 'git checkout *****'. 因此,我查看了我的git日志,找到了我喜欢的提交,然后键入'git checkout *****'。 It then makes the temporary branch (my noob understanding of it) which contains the earlier commit. 然后,它使包含早期提交的临时分支(我的菜鸟对此很了解)。 What do I to make this new branch back to 'master'? 如何使这个新分支恢复为“ master”?

You can reset current HEAD to specific commit by using reset command: 您可以使用reset命令将当前HEAD重置为特定提交:

git reset --hard <commit-id>

You need to checkout to current branch HEAD first( git checkout <branchname> ). 您需要先结帐到当前分支HEAD( git checkout <branchname> )。 Or git will do nothing. 否则git将无能为力。

Commit's that been after this commit will be forgotten by git, and will not be shown in history(but they can be easily restored from current repository reflog) git会忘记此提交之后的提交,并且不会在历史记录中显示(但可以从当前存储库reflog中轻松还原它们)

If you are looking to revert back to a previous commit and pretty much undo the work sense then, check out git reset. 如果您希望恢复到先前的提交并且几乎撤消了工作常识,请查看git reset。

git reset --hard <commit>

will reset the code to that commit. 将代码重置为该提交。

I would advise that you spend some time reading man git-reset first though, and perhaps make a backup just in case. 我建议您先花些时间阅读man git-reset,也许做个备份以防万一。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM