27

I just made some bad commits with egit that I would like to delete.

Some bad commits I want to delete

How do I delete commits from egit?

Thanks!

EDIT: I tried a hard reset a few times but it didn't do anything. Hard reset screen

EDIT 2: Hard reset does rollback changes indeed, but I want them to completely disappear from the history as if I never made these commits.

jobukkit
  • 2,490
  • 8
  • 26
  • 41
  • Here is my explanation on how to do it with egit interactive rebase : https://stackoverflow.com/a/70754367/3139370 – fayabobo Jan 18 '22 at 11:03

3 Answers3

40

RightMouse on your Repository and click on "show in -> history". You should select the last commit before your last "fetch"...most of the time its the second commit under your current HEAD. RightMouse on that commit and "reset -> Hard" (will reset all your commits AND local workspace changes to the selected commit).

you should see the up-arrow changing into an down-arrow, meaning that your commits are deleted and that your repository is outdated. Use "fetch" & "rebase" to be up to date.

Frank
  • 1,113
  • 3
  • 14
  • 27
  • "Fetch" fetches the remote repo in the local repo, and "rebase" asks for selecting another branch then the current branch... Didn't delete anything, only rolls back changes. Am I doing something wrong? – jobukkit Dec 10 '12 at 17:51
  • 1
    seems so, because rebase would normaly "update" your "outdated" files in the local repo or launch the conflict manager tool. if my instruction dont work for you -> setup a new egit when you have only bad commits on your repo. – Frank Dec 20 '12 at 14:45
  • Note that this didn't work for me. It worked locally, but it wouldn't let me push this change to the central repository. It rejected it for "non-fast-forward". What ended up working, which isn't quite what the OP asked for, was "Revert Commit". It let me push that to the central repo. – David M. Karr Aug 06 '21 at 20:18
  • 10 years later, this helped me – Wonka Jun 17 '22 at 09:34
5

Note that Egit3.0 in Kepler allows you to hard reset to any treeish expression you want:

enter image description here

But once hard reset, you still need to git push --force after that: if you don't the history of your upstream repo would still list that commit.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
-1

You can do a hard reset but be carefull with that !! Here's some more info: Delete commits from a branch in Git

Community
  • 1
  • 1
damiankolasa
  • 1,508
  • 9
  • 8
  • I have tried a hard reset a few times, but that didn't delete my commit... Am I doing something wrong? – jobukkit Nov 23 '12 at 19:04