How to delete latest Git commit in Bitbucket?
Asked Answered
W

5

7

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

Wry answered 14/3, 2016 at 4:35 Comment(0)
S
4

you can use git hard reset git reset documentation then you just need to force push your repository

Strade answered 14/3, 2016 at 4:43 Comment(1)
Hi @Taj , you have a simple answer but you are right. Thank youWry
H
6

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.

(source and more detail)

Hesper answered 14/3, 2016 at 4:43 Comment(1)
Thank you. You're a guruWry
S
4

you can use git hard reset git reset documentation then you just need to force push your repository

Strade answered 14/3, 2016 at 4:43 Comment(1)
Hi @Taj , you have a simple answer but you are right. Thank youWry
C
4

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.

Cispadane answered 14/3, 2016 at 4:44 Comment(0)
D
1

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,

Dempstor answered 14/3, 2016 at 4:54 Comment(0)
N
1

Git deletes the last commit from Bitbucket.

  1. $ git reset --hard HEAD~1

  2. $ git push -f

  • reset hard hard 1:  for delete
  • push -f:  for fix the commit server.
Nicholnichola answered 27/12, 2021 at 9:44 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.