Git-撤消推送的提交

本文翻译自:Git - Undo pushed commits

I have a project in a remote repository, synchronized with a local repository (development) and the server one (prod). 我在远程存储库中有一个项目,与本地存储库(开发)和服务器(产品)同步。 I've been making some commited changes already pushed to remote and pulled from the server. 我一直在进行一些已提交的更改,这些更改已推送到服务器并已从服务器拉出。 Now, I want to undo those changes. 现在,我要撤消那些更改。 So I could just git checkout to the commit before the changes and commit the new changes, but I'm guessing that there will be problems to push them again to remote. 因此,我可以在更改之前将git checkout到提交并提交新更改,但是我猜测将它们再次推送到远程将存在问题。 Any suggestion on how should I proceed? 关于如何进行的任何建议?


#1楼

参考:https://stackoom.com/question/1XAqk/Git-撤消推送的提交


#2楼

You can revert individual commits with: 您可以使用以下方法还原单个提交:

git revert <commit_hash>

This will create a new commit which reverts the changes of the commit you specified. 这将创建一个新的提交,该提交将还原您指定的提交的更改。 Note that it only reverts that specific commit, and not commits after that. 请注意,它仅还原特定的提交,之后不提交。 If you want to revert a range of commits, you can do it like this: 如果要还原一定范围的提交,可以这样进行:

git revert <oldest_commit_hash>..<latest_commit_hash>

It reverts the commits between and including the specified commits. 它还原指定提交之间(包括指定提交)的提交。

Look at the git-revert man page for more information about the git revert command. 查看git-revert手册页以获取有关git revert命令的更多信息。 Also look at this answer for more information about reverting commits.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要使用git reset --hard命令进行回退,并将更改到远程仓库,可以按照以下步骤进行操作: 1. 使用git log命令查找你需要回退的提交的commit id。 2. 运行git reset --hard <commit_id>命令,将代码回退到该commit_id对应的版本。 3. 使用git push origin HEAD --force命令,强制将本地回退后的更改到远程仓库。 请注意,使用--force参数时需要谨慎,因为它可以覆盖远程仓库的提交历史。确保您了解该操作的后果,并确保在执行之前做好必要的备份。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [git使用-烂笔头(1)git撤销 git reset --hard ********](https://blog.csdn.net/IDOshi201109/article/details/103688393)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] - *3* [来讲讲git reset --hard 和 git reset的区别吧 自己用到了 记录一下](https://blog.csdn.net/weixin_48986139/article/details/112261462)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT0_1"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值