如何删除推送到远程存储库的提交? [英] How to delete commit that is pushed to the remote repository?

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

问题描述

本地分行: -


'功能/ 100'


和远程分行: -
$ b


<主>'$ / b>


意外的是,


  1. 我已将我的功能分支功能/ 100合并到了主设备中。

但是真正的'特性/ 100 '应该已经合并到远程分支' Version2 '中。

我如何修正它(部分地)



我已经合并了功能分支 feature / 100 '到远程分支' Version2 '并将其推送到服务器。 $ b

  git checkout Version2 
git merge --squash feature / 100
git add。
git commit -m'新消息'

但是我想删除最后一次推送I已经合并并提交给主分支。如何?



注意事项我只是一个在这个项目上工作的人。所以,即使推送提交被删除,也不会伤害任何人

解决方案

您可以:

恢复您的更改

git revert HEAD



这将创建一个新的提交,恢复您刚刚推送给主控的更改。这是最安全的选择,因为其他人可能已经拉下了您推出的更改。



更改提交历史并强制推送更改




















git reset --hard HEAD〜1



git push origin master --force



除非您确定没有人从主人处取消您的更改,否则您不想这样做。



有关更多信息,请参阅从Git中的分支中删除提交


A local branch:-

'feature/100'

And Remote branches:-

'master'

'Version2'

Accidently,

  1. I have merged my feature branch 'feature/100' to the master
  2. Also pushed it to the remote repository.

But in real 'feature/100' should have been merged into remote branch 'Version2'

How I fixed it (partially):-

i have merged the feature branch 'feature/100' to the remote branch 'Version2' and pushed it to the server.

git checkout Version2
git merge --squash feature/100
git add .
git commit -m 'New message'

But I want to delete the last push I have merged and commit to the master branch. How?

Side Note I am only one working on this project.. So even if pushed commit is deleted it won't harm anyone else

解决方案

You can either:

Revert your change

git revert HEAD

This will create a new commit that reverts the changes that you just pushed up to master. This is the safest option because other people may have already pulled down the change that you have pushed up.

Change your commit history and force push the change

You can remove the commit that you just pushed up with:

git reset --hard HEAD~1

git push origin master --force

You don't want to do this unless you're absolutely sure that no one has pulled down your changes from master.

For more info, see Delete commits from a branch in Git

这篇关于如何删除推送到远程存储库的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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