回滚到公共存储库中的旧 Git 提交 [英] Rollback to an old Git commit in a public repo

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

问题描述

如何回滚到 git 中的特定提交?

How can I go about rolling back to a specific commit in git?

某人能给我的最佳答案是使用 git revert X 次,直到我达到所需的提交.

The best answer someone could give me was to use git revert X times until I reach the desired commit.

所以假设我想恢复到 20 次提交之前的提交,我必须运行它 20 次.

So let's say I want to revert back to a commit that's 20 commits old, I'd have to run it 20 times.

有没有更简单的方法来做到这一点?

Is there an easier way to do this?

我无法使用重置,因为此存储库是公开的.

I can't use reset because this repository is public.

推荐答案

试试这个:

git checkout [revision] .

其中 [revision] 是提交哈希(例如:12345678901234567890123456789012345678ab).

where [revision] is the commit hash (for example: 12345678901234567890123456789012345678ab).

不要忘记末尾的.,非常重要.这将对整个树应用更改.您应该在 git 项目根目录中执行此命令.如果您在任何子目录中,则此命令仅更改当前目录中的文件.然后提交,你应该会很好.

Don't forget the . at the end, very important. This will apply changes to the whole tree. You should execute this command in the git project root. If you are in any sub directory, then this command only changes the files in the current directory. Then commit and you should be good.

您可以通过以下方式撤消此操作

You can undo this by

git reset --hard 

这将从工作目录和暂存区中删除所有修改.

that will delete all modifications from the working directory and staging area.

这篇关于回滚到公共存储库中的旧 Git 提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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