How to delete a commit?

I'm using the Bitbucket (Git) with Netbeans. For some reason, a commit included a folder (build folder that contains binaries files, such as .class and .jar files) that was marked to be ignored. Now, I'm trying to delete the commit from repository and redo the commit.

2 answers

2 votes
Jason Worley Atlassian Team Jul 30, 2013

You can look into the git revert command. More info available here:

https://www.atlassian.com/git/tutorial/undoing-changes#!revert

If the commit has not yet been pushed, you can use `git reset` to reset the branch to the commit before the bad commit. Beware that this changes git history and you will lose the commit(s) on the branch that occurred after the commit to which you reset the branch to.  

Note: If the commit has already been pushed, you can still technically use `git reset`, but you will then have to use `--force` when pushing, which will overwrite git history on your remote git repository. Overwriting git history can be acceptable in some cases, but it is not a good idea in many cases, such as if other developers have checked out the same branch.
Also: remote repositories can be configured to prevent history re-writing, in which case you should not use `git reset` to remove pushed commits. 

Suggest an answer

Log in or Join to answer

Stay in touch

Be the first to know what's trending on Atlassian Community