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

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

问题描述

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

为什么?

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

我想变基,如本例所示:我该如何删除 GitHub 上的提交?

然而,git 要我做很多冲突管理.有没有更简单的方法?

解决方案

git reset --hard 

git push -f <远程名称><分支机构名称>

注意:正如下面的评论中所写,在协作环境中使用它是危险的:您正在重写历史

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

Why?

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.

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

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天全站免登陆