简体   繁体   English

使用 Github Revert Button 恢复 PR 后如何再次 PR 和合并

[英]How to PR and merge again after reverting PR using Github Revert Button

Basically I used Github revert button to revert a previous PR for a feature branch into master , then I decided to merge the same feature branch that I reverted earlier, but I was not able to do so.基本上我使用Github 恢复按钮功能分支的先前 PR 恢复到master ,然后我决定合并我之前恢复的相同功能分支,但我无法这样做。 Steps as follow:步骤如下:

  1. PR to merge feature branch to master PR 将功能分支合并到master
  2. Revert PR merge from ( master )从( master )恢复 PR 合并
  3. Tried to create new PR to merge feature branch to master again.尝试创建新 PR 以再次将功能分支合并到master
  4. Got this message:收到这条消息:

There isn't anything to compare.没有什么可以比较的。

master is up to date with all commits from feature-branch. master 与来自 feature-branch 的所有提交保持同步。 Try switching the base for your comparison.尝试切换基准进行比较。

Any suggestions on how can I merge feature branch again into master关于如何将功能分支再次合并到master分支的任何建议

Just revert the revert.只需还原还原即可。 So by clicking the revert button you will have created a new PR (your step 2).因此,通过单击还原按钮,您将创建一个新的 PR(您的第 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.合并后,您可以选择还原它,这将创建一个包含所有更改的新分支。然后您可以拉取它,对其进行更改(如果需要)并创建一个新的 PR。 You will lose all the commit messages on Github, but all file changes will still be around.您将丢失 Github 上的所有提交消息,但所有文件更改仍然存在。 Good to refer to your original branch and reverts in the new PR.很高兴参考您的原始分支并在新的 PR 中恢复。

Anything to avoid a complicated rebase or force pushing to master.任何避免复杂的 rebase 或强制推送到 master 的东西。

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 .为了解决这个问题,你必须创建一个新的分支来跟踪 master 并恢复 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.现在你可以解决冲突(如果有的话),提交并创建一个新的 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

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.在合并 PR 并删除分支并稍后还原此合并后,您可以创建一个新分支,然后还原还原。 Push this to remote repo and create a new 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

What什么

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 上,然后您应该能够发出另一个拉取请求。


Why为什么

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.假设您在 master 上有特征 x 并合并到分支 y 中。 then you decide master shouldn't have had feature x merged in yet as it depends on branch y.那么你决定 master 不应该有特征 x 合并,因为它取决于分支 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.当您尝试合并分支 x 时,git-merge 命令会看到原始合并,并高兴地宣布一切正常并且分支已经合并,即使您希望它们与分支 y 合并,也省略了对功能 x 的这些提交。

  1. Go the the Revert PR and click "Revert" (But don't merge it)转到 Revert PR 并单击“Revert”(但不要合并它)
  2. Do git fetchgit fetch
  3. Do git checkout <name of revert's revert> Do git checkout <name of revert's revert>

All your changes will be there, and when you create a PR, the changes will show.您的所有更改都会在那里,当您创建 PR 时,这些更改就会显示出来。

To be clear - Clicking "Revert" on the Revert PR will give you a name like revert-202-revert-201-originalbranchname .需要明确的是——点击 Revert PR 上的“Revert”会给你一个像revert-202-revert-201-originalbranchname这样的名字。 This is the branch you want to edit on!这是您要编辑的分支!

Here is what i did.这是我所做的。

  1. checkout your feature branch签出您的功能分支

  2. Rebase with your base branch: This will bring your feature branch to the state of Base branch because your feature branch commits are already a part of the base branch.使用您的基本分支重新绑定:这将使您的功能分支进入基本分支的状态,因为您的功能分支提交已经是基本分支的一部分。 Your feature branch commits will be aligned below your revert PR commit.您的功能分支提交将在您的恢复 PR 提交下方对齐。

  3. Then revert the commit that reverted your PR.然后恢复恢复 PR 的提交。 This will bring your feature branch back to its original state but now with a new commit.这将使您的功能分支恢复到其原始状态,但现在有了新的提交。

  4. push to feature branch and then raise a PR.推送到功能分支,然后提出 PR。

Why this works?为什么这有效? by rebasing you bring your feature branch in sync with the base ie bring it to equal commits as the base- needed to move ahead of base and also get the commit that reverted your changes onto your feature branch通过变基,您可以使您的功能分支与基础分支同步,即使其与基础提交相同的提交 - 需要在基础之前移动并获得将您的更改恢复到您的功能分支的提交

by reverting you reverse the changes that removed your changes and now your changes can be a part of new commit AHEAD of based branch.通过恢复,您可以撤消删除您的更改的更改,现在您的更改可以成为基于分支的新提交 AHEAD 的一部分。

  1. Switch to the master branch and print out the commit logs git log .切换到 master 分支并打印出提交日志git log Here search the commit that was made for the PR and copy the commit hash code.在这里搜索为 PR 所做的提交并复制提交哈希代码。
  2. Now run git cherry-pick YOUR_HASH_CODE .现在运行git cherry-pick YOUR_HASH_CODE This will bring your that particular commit to top of the head.这将使您的特定承诺成为首要任务。
  3. Now create a new branch and switch to this newly created branch and push it to git.现在创建一个新分支并切换到这个新创建的分支并将其推送到 git。
  4. Now create a PR to master from this newly created branch.现在从这个新创建的分支创建一个 PR 来掌握。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM