[英]How to reset the changes that were pushed to git and then merged with another branch?
I pushed some changes on git, by mistake. 我错误地对git进行了一些更改。 And then those changes were merged with another branch.
然后将这些更改与另一个分支合并。 Because of merging I am unable to reset the changes in initial branch.
由于合并,我无法重置初始分支中的更改。
How should I reset the changes that were pushed by mistake? 我应该如何重置被错误推送的更改?
You might consider reverting to a good state and pushing the commits that fix the mistake. 您可能会考虑恢复到良好状态并推送可修复错误的提交。 This keeps the mistake in the history, but requires less coordination with anyone who has pulled your broken changes, and other branches can be fixed simply by merging.
这样可以将错误保留在历史记录中,但需要与拉扯您的无效更改的任何人进行较少的协调,并且可以简单地通过合并来修复其他分支。
The problem with resetting and pushing a shared branch is that the broken changes still appear in others' repos and branches. 重置和推送共享分支的问题在于,破碎的更改仍会出现在其他人的存储库和分支中。
If you really want to reset the branch: 如果您确实要重置分支:
Assuming the master
branch started from a commit we'll call good
, on top of which were added commits we'll call broken
. 假设
master
分支是从一个commit开始的,我们将其称为good
,在此基础上添加的commit将被称为broken
。 The feature
branch was branched off master
and started with a few commits we'll call before
, then was merged with master
(which was broken
) in a commit we'll call merge-broken
, and other commits were made on top of that, we'll call them after-broken
. feature
分支是从master
分支出来的,从我们before
调用before
的几次提交开始,然后在一次我们称为merge-broken
的提交中与master
(已broken
) merge-broken
,在此之上进行了其他提交,我们称它们after-broken
。
Here's how these branches might get fixed, discarding other changes to the master
and feature
branches: 这些分支的固定方法如下,丢弃了对
master
和feature
分支的其他更改:
git branch -f master good
git branch -f feature before
git checkout feature
git merge master
git cherry-pick merge-broken..after-broken
These changes can be pushed upstream, but as mentioned above this might be dangerous in a public or shared repo: 这些更改可以向上游推送,但是如上所述,在公共或共享回购中这可能很危险:
git push origin +master +feature
Other users may need to pull those branches with the --force
flag, and may need to adjust their local branches in the same way. 其他用户可能需要使用
--force
标志拉那些分支,并且可能需要以相同的方式调整其本地分支。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.