简体   繁体   English

从主分支恢复合并的拉取请求

[英]Revert a merged pull request from master branch

I have accidentally merged pull request into master branch from my feature branch, which i should not have.我不小心merged拉取请求从我的功能分支合并到master分支,这是我不应该的。 I am using gogs .我正在使用gogs I cannot use revert button as there is not any functionality available.我无法使用还原按钮,因为没有任何功能可用。 How can i revert back the master to the position before my pull request so that master branch will be clean again.在我的拉取请求之前,我如何将主分支恢复到 position 以便主分支将再次干净。

Also master branch is protected and commits should be pushed only through pull request.主分支也受到保护,提交只能通过拉取请求推送。 So git push -f is not working for me.所以git push -f对我不起作用。

I have read other questions but they were about a specific incidents.我读过其他问题,但它们是关于特定事件的。 I am not sure how can i achieve this.我不知道我怎么能做到这一点。

If you have not added any other commit after the wrong merge I suggest you tu rely on the command line as follow:如果您在错误合并后没有添加任何其他提交,我建议您依赖命令行,如下所示:

git checkout master
git pull

git log --oneline --graph --decorate # Write down the hash of the last good commit

git reset --hard {{last-good-commit-hash}}

# Review your commits, and if it all right...

git push --force # Rewrite branch history, be carefully!!!

I have had the same problem before.我以前也遇到过同样的问题。 Going to the commit you want to revert to and hitting the revert button in Gogs is what you are supposed to do.转到您想要恢复的提交并点击 Gogs 中的恢复按钮是您应该做的。

If that doesn't work: Every commit with Git has a commit hash connected to it.如果这不起作用:每个带有 Git 的提交都有一个提交 hash 连接到它。 This should be listed in the history of commits on the Gogs page.这应该列在 Gogs 页面上的提交历史中。 There should be a button to easily copy any hash, so you don't have to type it out.应该有一个按钮可以轻松复制任何 hash,因此您不必输入它。 If you can use a command line console, you can use "git revert [code]" where code is the commit hash linked to the earlier commit.如果您可以使用命令行控制台,则可以使用“git revert [code]”,其中代码是链接到先前提交的提交 hash。 After that, "git push".之后,“git push”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何还原master的合并分支? - How to revert back the merged branch from master? 从主分支恢复合并的更改 - Revert merged changes from master branch 还原合并的拉取请求 - Revert a merged pull request 在 Bitbucket 上恢复合并的拉取请求 - Revert a merged pull request on Bitbucket Git在拉取请求分支上还原樱桃选择,而在主节点上不还原 - Git revert cherry pick on pull request branch without reverting on master 如何恢复合并到我分叉的仓库的拉取请求,而不是合并到我的该仓库副本 - How to revert a pull request that was merged to repo I forked from, instead being merged to my copy of that repo 如何使用合并的分支从 TFS 拉取请求中对 Jenkins 作业进行排队 - How to queue Jenkins job from TFS pull request with merged branch 将代码从分支拉至本地并在本地进行测试,然后将本地恢复为主版本,而无需对分支进行任何更改 - Pull the code from branch to local and test in local, then revert the local to master without carrying any changes from branch 如果合并或重新设置了主删除分支文件中的主Git`revert` - Git `revert` in master deleting branch files if merged or rebased 我可以使用相同的分支来恢复合并到 master 的更改吗 - Can I use same branch to revert changes which is merged to master
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM