Git – removing a commit

I forked a repo on Github a few months ago, and have made three commits. I’d like to submit a pull request with some bug fixes back to the original project, but one of the commits had some changes which don’t apply to them.

How on earth do I fix this? I’m coming from an svn background, so most of the terminology, etc. has a very different meaning that I’d expect.

  • Creating remote repository out of local ones, Pycharm
  • Split large Git repository into many smaller ones
  • Applying commits from one subtree to another in same repo
  • What does // refer to when you have nested Buck projects?
  • How to make dependencies between merged patch and before merged patch in gerrit?
  • bad numeric config value 'tru' for 'core.longpaths': invalid unit
  • How to deal with merge/pull in git
  • How to add an existing project in WEB IDE to the Git?
  • Git pull origin/master branch to local/master, when in local/develop
  • How to migrate gitlab backups to new server which has latest gitlab version
  • replace remote repository with local repo, but keep commit history of remote
  • Jenkins: running build does not provision docker slave
  • 2 Solutions collect form web for “Git – removing a commit”

    Create a new branch with only the changes you want, and submit a pull request from that instead of your master. Doing git branch origin my-new-branch-name will create a new branch you can work on without any changes from your work. Then git checkout my-new-branch-name will start work on it. Then apply your changes with e.g. git cherry-pick my_commit_id_1 my_commit_id_1. Finally git push ssh://remote.host/path/to/repo my-new-branch-name will push it to the server from which you can issue a pull request.

    To just get rid of the commit, you can do the following.

    • Run git log to get the hash of the commit that you want to get rid of
    • Run git rebase --interactive abc123^, where abc123 is the hash of the bad commit
    • Delete the bad commit from the list that pops up in your editor (delete the line with that commit: leave the other lines)
    • Save and close the editor, and Git will rebase all later commits onto the parent of the bad commit
    Git Baby is a git and github fan, let's start git clone.