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.
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.
git logto get the hash of the commit that you want to get rid of
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