Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove commits from a 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's 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.

enter image description here

my git log enter image description here

Can someone please explain what's going on and how to fix this problem?

like image 564
humazed Avatar asked Mar 23 '16 02:03

humazed


People also ask

Can you remove a commit from a pull request?

Step-1: Make sure your working directory is clean ( commit or stash your current changes). Step-2: One can use the git-rebase command to easily make changes to one's history. After running the git rebase command you get the following in your $EDITOR: Step-3: Replace pick with drop to “drop” the commit.

Can you remove commits from github?

To remove the last commit from git, you can simply run git reset --hard HEAD^ If you are removing multiple commits from the top, you can run git reset HEAD~2 to remove the last two commits. You can increase the number to remove even more commits.

How do you remove changes from a pull request?

If the file change is simple and the PR is still open, just go to your branch, modify the file back to the way it was originally and then commit and push your change. Your PR should be updated and the file will disappear if it exactly matches the target branch.

How do I remove a specific commit?

Simplest way, Just look for the log and have a count which commits and check out the commit-msg which you want to drop. Replace x with the count, I will show all the commit-msg, just delete the commit-msg which you want to remove.


2 Answers

People wouldn't like to see a wrong commit and a revert commit to undo changes of the wrong commit. This pollutes commit history.

Here is a simple way for removing the wrong commit instead of undoing changes with a revert commit.

  1. git checkout my-pull-request-branch

  2. git rebase -i HEAD~n // where n is the number of last commits you want to include in interactive rebase.

  3. Replace pick with drop for commits you want to discard.
  4. Save and exit.
  5. git push --force
like image 70
ferit Avatar answered Sep 19 '22 20:09

ferit


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.

like image 33
CodeWizard Avatar answered Sep 17 '22 20:09

CodeWizard