How to delete latest Git commit in Bitbucket?
Solution 1
you can use git hard reset git reset documentation then you just need to force push your repository
Solution 2
Start by undoing that last commit in your local repository:
If you want to uncommit but keep the changes in the file tree, use
git reset HEAD~1
If you want to completely get rid of the changes, run
git reset --hard HEAD~1
Next, push your repository to bitbucket.
Solution 3
git reset --soft HEAD^
First, remove the commit on your local repository. You can do this using git rebase -i
. For example, if it's your last commit, you can do git rebase -i HEAD~2
and delete the second line within the editor window that pops up.
Then, force push to your rep by using git push origin +master
.
See Git Magic Chapter 5: Lessons of History - And Then Some for more information (i.e. if you want to remove older commits).
please see alternative to
git rebase -i
working tree is dirty, you have to do a git stash
first, and then a git stash apply
after.
Solution 4
Check this post out:
How to move HEAD back to a previous location? (Detached head)
It will describe methods for doing so.
But keep in mind that if your server does not allow force push you will not be able to to push old commit HEAD to the server,
Solution 5
Git deletes the last commit from Bitbucket.
-
$ git reset --hard HEAD~1
-
$ git push -f
- reset hard hard 1: for delete
- push -f: for fix the commit server.
redshot
I am Front End Developer with 7+ years worth of experience, I have had the opportunity to strengthen my knowledge of front-end technologies and this includes working on front-end(HTML5, CSS3, GULP, SASS, JavaScript, ES6, jQuery, AJAX, Angular, ReactJS) and back-end(PHP, MySQL, REST API).
Updated on June 14, 2022Comments
-
redshot almost 2 years
I am storing laravel files in bitbucket and I also have a local copy of the project. Every time i save my local copy, i push it to the remote repository in bitbucket so that they have the same update.
Problem: I made a mistake in my local project and I want to delete the latest commit in Remote Repository in bitbucket.
Does anyone know how to remove/delete the latest commit in bitbucket?
Thanks
-
redshot about 8 yearsHi @Taj , you have a simple answer but you are right. Thank you
-
redshot about 8 yearsThank you. You're a guru