It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

How to delete a commit?

Rafael Santini Jul 26, 2013

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

3 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

1 vote
Russell Spivey May 08, 2017 • edited

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.  

Russell Spivey May 08, 2017

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 Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published in Bitbucket Pipelines

Building a Bitbucket Pipe as a casual coder

...ipe.sh :  #!/bin/bash source "$(dirname "$0")/common.sh" enable_debug extra_args="" if [[ "${DEBUG}" == "true" ]]; then extra_args="--verbose" fi # mandatory variables R...

1,651 views 1 18
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you