git 使用 Github Revert Button 恢复 PR 后如何再次 PR 和合并
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/27852143/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to PR and merge again after reverting PR using Github Revert Button
提问by Aboodred1
Basically I used Github revert buttonto revert a previous PR for a feature branchinto master
, then I decided to merge the same feature branchthat I reverted earlier, but I was not able to do so. Steps as follow:
基本上,我使用Github的恢复按钮,恢复以前的PR的特性分支到master
,然后我决定合并相同的特性分支我之前恢复,但我不能这样做。步骤如下:
- PR to merge feature branchto
master
- Revert PR merge from (
master
) - Tried to create new PR to merge feature branch to
master
again. - Got this message:
- PR 将功能分支合并到
master
- 从 (
master
)恢复 PR 合并 - 尝试创建新 PR 以
master
再次合并功能分支。 - 收到这条消息:
There isn't anything to compare.
master is up to date with all commits from feature-branch. Try switching the base for your comparison.
没有什么可以比较的。
master 与来自 feature-branch 的所有提交保持同步。尝试切换基准进行比较。
Any suggestions on how can I merge feature branchagain into master
关于如何将功能分支再次合并到的任何建议master
回答by Anthony
Just revert the revert. So by clicking the revert button you will have created a new PR (your step 2). Once this is merged, you will have the option to revert this, which will create a new branch with all your changes back in. You can then pull this, make changes to it (if needed) and create a new PR. You will lose all the commit messages on Github, but all file changes will still be around. Good to refer to your original branch and reverts in the new PR.
只需还原还原即可。因此,通过单击还原按钮,您将创建一个新的 PR(您的第 2 步)。合并后,您可以选择还原它,这将创建一个包含所有更改的新分支。然后您可以拉取它,对其进行更改(如果需要)并创建一个新的 PR。您将丢失 Github 上的所有提交消息,但所有文件更改仍然存在。很高兴参考您的原始分支并在新 PR 中恢复。
Anything to avoid a complicated rebase or force pushing to master.
任何避免复杂的 rebase 或强制推送到 master 的东西。
回答by Shanika Ediriweera
I am writing this answer since I faced this issue and I found the answers here more theoretical than practical. I surfed a little bit more and found the method to tackle this issue. You can find a more detailed answer in the article here.
我写这个答案是因为我遇到了这个问题,我发现这里的答案更具理论性而不是实践性。我浏览了一点,找到了解决这个问题的方法。您可以在此处的文章中找到更详细的答案。
To solve this problem you have to create a new branch tracking the master and revert the revert commit. Then checkout to feature branch and merge the new branch. Now you can resolve conflicts (if any), commit and create a new PR.
为了解决这个问题,你必须创建一个新的分支来跟踪 master 并恢复 revert commit。然后结帐到功能分支并合并新分支。现在你可以解决冲突(如果有的话),提交并创建一个新的 PR。
Here are the commands:
以下是命令:
# do the needed changes in the feature branch
$ git commit -m "fixed issues in feature-branch'
# create new branch tracking master branch
$ git checkout -b revert-the-revert-branch -t master
# revert the reversion commit
# find it from your git log
# in linux try: 'git log | grep revert -A 5 -B 5'
$ git revert <revert-commit-hash>
# checkout the original feature branch
$ git checkout feature-branch
# merge the revert branch
$ git merge revert-the-revert-branch
# handle merge conflicts and commit and PR
回答by Michelle Diniz
I know this is old, but if someone need a good answer is here:
我知道这很旧,但如果有人需要一个好的答案,请点击此处:
After you merge a PR and delete the brach and later revert this merge, you can create a new branch and then revert the revert. Push this to remote repo and create a new PR.
在合并 PR 并删除分支并稍后还原此合并后,您可以创建一个新分支,然后还原还原。将其推送到远程仓库并创建一个新的 PR。
This will create a new PR with one commit named 'revert "revert #123 blabla"` with all your changes on diff.
这将创建一个新的 PR,其中包含一个名为“revert "revert #123 blabla"”的提交,其中包含您对 diff 的所有更改。
https://www.tildedave.com/2012/11/24/reverting-a-github-pull-request.html
https://www.tildedave.com/2012/11/24/reverting-a-github-pull-request.html
回答by theannouncer
The reason you can't auto merge back in is because the base of the branch is out of sync with the HEAD of the master branch.
您不能自动合并回的原因是因为分支的基础与主分支的 HEAD 不同步。
Reverting the Revert can get messy and sometimes lacks transparency.
恢复 Revert 可能会变得混乱,有时缺乏透明度。
Furthermore, reverting a revert will prevent other branches with this code from merging correctly.
此外,还原还原将阻止具有此代码的其他分支正确合并。
Lets say you have feature x on master and merged into branch y. then you decide master shouldn't have had feature x merged in yet as it depends on branch y. So, you revert on master. When you try to merge branch x, git-merge command sees the original merge, and happily announces that all is well and branches have been already merged, omitting these commit for feature x, even though you wanted them merged with branch y.
假设您在 master 上有特征 x 并合并到分支 y 中。那么你决定 master 不应该有特征 x 合并,因为它取决于分支 y。所以,你恢复了主人。当您尝试合并分支 x 时,git-merge 命令会看到原始合并,并高兴地宣布一切正常并且分支已经合并,即使您希望它们与分支 y 合并,也省略了对功能 x 的这些提交。
You should pull the most recent master, rebase your branch on master and then you should be able to make another pull request.
您应该拉取最新的 master,将您的分支重新建立在 master 上,然后您应该能够发出另一个拉取请求。