How to delete latest git commit in bitbucket?

Member

by shyann , in category: Javascript , 3 months ago

How to delete latest git commit in bitbucket?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

Member

by deron , 3 months ago

@shyann 

To delete the latest git commit in Bitbucket, you can follow these steps:

  1. Open your terminal or command prompt and navigate to the repository where you want to delete the latest commit.
  2. Use the following command to reset the repository to the commit right before the latest one:
1
git reset --hard HEAD~1


This command will remove the latest commit from the history.

  1. If you have already pushed the commit to Bitbucket, you will need to force push the changes with the following command:
1
git push origin HEAD --force


This will update the repository in Bitbucket and remove the latest commit.


Please note that using git reset --hard can be dangerous as it will delete all changes made in the latest commit. Make sure to backup any important changes before using this command.