你如何回滚(重置)Git仓库到特定的提交? [英] How do you roll back (reset) a Git repository to a particular commit?

查看:1020
本文介绍了你如何回滚(重置)Git仓库到特定的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我克隆了一个Git仓库,然后在开发过程的早期尝试将其推回到特定的提交。在那之后添加到存储库中的所有内容对我来说都是不重要的,所以我想从我的本地源代码中省略所有后续更改。

然而,当我尝试滚动回到GUI工具中,它不会更新我的本地文件系统 - 我总是以项目的最新源代码结束。



刚刚获得的正确方法是什么作为项目历史记录中特定提交的存储库源,并忽略所有后来的更新?

  git reset --hard< tag / branch / commit id> 






em>




  • git reset c $ c> - hard 选项会重置提交历史记录,但不会重置文件。使用 - hard 选项,工作树中的文件也会重置。 (贷记用户

  • 如果您希望提交该状态以便远程存储库也指向回滚提交执行: git push< reponame> -f 贷记用户

I cloned a Git repository and then tried to roll it back to a particular commit early on in the development process. Everything that was added to the repository after that point is unimportant to me so I want to omit all subsequent changes from my local source code.

However, when I try to roll back in the GUI tool it doesn't update my local file system - I always end up with the latest source code for the project.

What's the correct way to just get the source for a repository as of a particular commit in the project's history and omit all later updates?

解决方案

git reset --hard <tag/branch/commit id>


Notes:

  • git reset without the --hard option resets the commit history, but not the files. With the --hard option the files in working tree are also reset. (credited user)

  • If you wish to commit that state so that the remote repository also points to the rolled back commit do: git push <reponame> -f (credited user)

这篇关于你如何回滚(重置)Git仓库到特定的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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