How to remove commits from pull request

I did a pull request but after that I made some commits to the project locally which ended polluting my pull request, I tried to remove it but without any luck.

I found some similar questions on StackOverflow but I can't apply what in there. It's my first pull request on GitHub so it's kinda strange to me how all of this works.

the highlighted commit is the one I need to keep and remove all the other stuff. it becomes the fourth commit in the history because I make some merge stuff.

在这里输入图像描述

my git log 在这里输入图像描述

can someone please explain what's going on and how to fix this problem.


You have several techniques to do it.

This post - read the part about the revert will explain in details what we want to do and how to do it.

Here is the most simple solution to your problem:

# Checkout the desired branch
git checkout <branch>

# Undo the desired commit
git revert <commit>

# Update the remote with the undo of the code
git push origin <branch>

The revert command will create a new commit with the undo of the original commit.


So do the following ,

Lets say your branch name is my_branch and this has the extra commits.

  • git checkout -b my_branch_with_extra_commits (Keeping this branch saved under a different name)
  • gitk(Opens git console)
  • Look for the commit you want to keep. Copy the SHA of that commit to a notepad.
  • git checkout my_branch
  • gitk (This will open the git console )
  • Right click on the commit you want to revert to(State before your changes) and click on "reset branch to here"
  • Do a git pull --rebase origin branch_name_to _merge_to
  • Git cherry-pick
  • Now look at the local branch commit history and make sure everything looks good.

    链接地址: http://www.djcxy.com/p/18818.html

    上一篇: 我无法签出特定的分支,“脱离HEAD状态”

    下一篇: 如何从拉取请求中移除提交