简体   繁体   English

如何重置推送到git然后与另一个分支合并的更改?

[英]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 (已brokenmerge-broken ,在此之上进行了其他提交,我们称它们after-broken

Here's how these branches might get fixed, discarding other changes to the master and feature branches: 这些分支的固定方法如下,丢弃了对masterfeature分支的其他更改:

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.

相关问题 Git:如何像将其与另一个分支合并一样提交更改? - Git: how to commit changes as if it were a merge with another branch? 如何判断给定git分支的最后一次提交合并到另一个分支中,以查找对该分支所做的更改? - How to tell the last commit of a given git branch merged into another branch to find changes made on the branch? 如何移动已推送到主用户而不是功能分支的其他用户的更改? - How to move another user's changes that were pushed to master instead of feature branch? 如何将远程主服务器重置回尚未与git中的另一个分支合并的提交 - How to reset remote master back to a commit which has not been merged with another branch in git 重置推送的更改git存储库 - Reset pushed changes git repository 使用 git reset 还原合并的更改 - Revert merged changes with git reset 如何使用 git 将一个分支重置为另一个分支? - How to reset a branch to another branch with git? git:如何使用另一个分支的内容重置分支? - git: How to reset branch with contents of another branch? 检查分支更改是否被手动合并 - Check whether branch changes were manually merged 将 Master 合并到分支中,然后提交并将更改推送到分支。 如果没有强制推动,这怎么能撤消? - Merged Master into branch then committed and pushed changes to branch. How can this be undone without a force push?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM