如何将git存储库回滚到特定提交? [英] How can I rollback a git repository to a specific commit?

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

问题描述

我的仓库现在有100个提交.我需要回滚存储库以提交80,并删除所有后续存储库.

My repo has 100 commits in it right now. I need to rollback the repository to commit 80, and remove all the subsequent ones.

为什么?

该回购应该用于其他用户的合并.由于过度的编辑,一堆合并作为我提交的内容.那是由于我的远程分支贴错了标签,在那里3个开发人员被标记为彼此.我需要重置到该点,然后向前拉.

This repo is supposed to be for merging from miscellaneous users. A bunch of merges went in as commits from me, due to excessive editing. That was due to a mislabeling of my remote branches, where 3 developers were labeled as each other. I need to reset to that point, and then pull forwards.

我想重新设置基准,例如以下示例:如何删除GitHub上的提交?

I wanted to rebase, as in this example: How can I remove a commit on GitHub?

但是,git希望我做很多冲突管理.有没有更简单的方法?

However, git wants me to do a lot of conflict management. Is there a simpler way?

推荐答案

git reset --hard <old-commit-id>
git push -f <remote-name> <branch-name>

注意:如下面的评论所述,在协作环境中使用此操作很危险:您正在重写历史记录

Note: As written in comments below, Using this is dangerous in a collaborative environment: you're rewriting history

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

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