Skip to contentSkip to conversation

Delete a commit

DISCUSSION Bertram Scharpf 5 participants 8 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

Hi,

I fetched a line from the shell's history and accidentally hit enter before editing it. Then I had commited some work that was not completed. Is there a way to get rid of that commit as if it never were there?

Thanks in advance.

Bertram

Signature · 3 lines
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
#1 lore raw
Quoted 4 lines · Bertram Scharpf

I fetched a line from the shell's history and accidentally hit enter before editing it. Then I had commited some work that was not completed. Is there a way to get rid of that commit as if it never were there?

If you have committed nothing else in the interim,

git reset HEAD~1

James

Signature · 2 lines
James P. Howard, II, MPA MBCS
[email protected]
#2 lore raw
In reply to Bertram Scharpf

Bertram Scharpf schreef:

Quoted 6 lines

Hi,

I fetched a line from the shell's history and accidentally hit enter before editing it. Then I had commited some work that was not completed. Is there a way to get rid of that commit as if it never were there?

Try:
git reset --soft HEAD~1

You could also:
git commit --amend ...

when you realy finish the commit.

Quoted 6 lines

Thanks in advance.

Bertram

#3 lore raw

Hi,

Am Sonntag, 20. Dez 2009, 01:06:46 +0100 schrieb Johan 't Hart:

Quoted 11 lines

Bertram Scharpf schreef:

Quoted 4 lines

I fetched a line from the shell's history and accidentally hit enter before editing it. Then I had commited some work that was not completed. Is there a way to get rid of that commit as if it never were there?

Try:
git reset --soft HEAD~1

You could also:
git commit --amend ...

  % git fsck --lost-found
  dangling commit 6abc221327e896c850c56dafae92277bcfe68e2b

It is still there. This is the one I want to delete.

Bertram

Signature · 3 lines
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
#4 lore raw
Quoted 4 lines · Bertram Scharpf
  % git fsck --lost-found
  dangling commit 6abc221327e896c850c56dafae92277bcfe68e2b

It is still there. This is the one I want to delete.

Well, it is deleted (not accessible from any ref). It will be purged from the repository at some point after a "git gc".

Signature · 8 lines
--|------------------------------------------------------
--| Pascal Obry                           Team-Ada Member
--| 45, rue Gabriel Peri - 78114 Magny Les Hameaux FRANCE
--|------------------------------------------------------
--|    http://www.obry.net  -  http://v2p.fr.eu.org
--| "The best way to travel is by means of imagination"
--|
--| gpg --keyserver keys.gnupg.net --recv-key F949BD3B
#5 lore raw
In reply to Bertram Scharpf

Bertram Scharpf schreef:

Quoted 6 lines

Hi,

  % git fsck --lost-found
  dangling commit 6abc221327e896c850c56dafae92277bcfe68e2b

It is still there. This is the one I want to delete.

It is not in the history of any head anymore, so you could consider it deleted. ('git log' does not show this commit)

If you want to prune unreferenced objects, try:
git prune

('git help prune' for options)

Quoted 3 lines

Bertram

#6 lore raw

Hi,

Am Montag, 21. Dez 2009, 18:49:36 +0100 schrieb Johan 't Hart:

Quoted 6 lines

Bertram Scharpf schreef:

Quoted 3 lines

% git fsck --lost-found
dangling commit 6abc221327e896c850c56dafae92277bcfe68e2b
It is still there. This is the one I want to delete.

Quoted 7 lines

It is not in the history of any head anymore, so you could consider it deleted. ('git log' does not show this commit)

If you want to prune unreferenced objects, try:
git prune

('git help prune' for options)

In the meantime I detected the gc.pruneExpire config variable. I didn't get that to work on all versions that I have installed on different machines, but I just wanted to understand what has to happen with the commit.

Thank you!

Bertram

Signature · 3 lines
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
#7 lore raw
In reply to Johan 't Hart
Quoted 10 lines · Johan 't Hart

Bertram Scharpf schreef:

Quoted 6 lines

Hi,

  % git fsck --lost-found
  dangling commit 6abc221327e896c850c56dafae92277bcfe68e2b

It is still there. This is the one I want to delete.

It is not in the history of any head anymore, so you could consider it deleted. ('git log' does not show this commit)

Except through the reflog, most likely.

Andreas.

Signature · 3 lines
Andreas Schwab, [email protected]
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."