threads / discuss / 21994

Delete a commit

Subject: Delete a commit

## tl;dr

8 messages between Dec 19, 2009 and Dec 21, 2009.

replies: 7people: 5as markdown or json

Bertram Scharpf· Dec 19, 2009, 23:39 UTC · lore
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
-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
James P. Howard, II· Dec 19, 2009, 23:43 UTC · re: Bertram Scharpf · lore

Re: Delete a commit

On Sun, Dec 20, 2009 at 12:39:57AM +0100, Bertram Scharpf wrote:
> 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
-- 
James P. Howard, II, MPA MBCS
jh@jameshoward.us
Johan 't Hart· Dec 20, 2009, 00:06 UTC · re: Bertram Scharpf · lore

Re: Delete a commit

Bertram Scharpf schreef:
Show 6 quoted 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.
Show 6 quoted lines
> 
> Thanks in advance.
> 
> Bertram
> 
> 
Bertram Scharpf· Dec 20, 2009, 00:43 UTC · re: Johan 't Hart · lore

Re: Delete a commit

Hi,
Am Sonntag, 20. Dez 2009, 01:06:46 +0100 schrieb Johan 't Hart:
Show 11 quoted lines
> Bertram Scharpf schreef:
>> 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
-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de
Pascal Obry· Dec 20, 2009, 08:37 UTC · re: Bertram Scharpf · lore

Re: Delete a commit

Le 20/12/2009 01:43, Bertram Scharpf a écrit :
>   % 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".

-- 
--|------------------------------------------------------
--| 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
Johan 't Hart· Dec 21, 2009, 17:49 UTC · re: Bertram Scharpf · lore

Re: Delete a commit

Bertram Scharpf schreef:
> 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)
> Bertram
> 
> 
Andreas Schwab· Dec 21, 2009, 18:17 UTC · re: Johan 't Hart · lore

Re: Delete a commit

Johan 't Hart <johanthart@gmail.com> writes:
Show 10 quoted lines
> Bertram Scharpf schreef:
>> 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.
-- 
Andreas Schwab, schwab@linux-m68k.org
GPG Key fingerprint = 58CA 54C7 6D53 942B 1756  01D3 44D5 214B 8276 4ED5
"And now for something completely different."
Bertram Scharpf· Dec 21, 2009, 21:01 UTC · re: Johan 't Hart · lore

Re: Delete a commit

Hi,
Am Montag, 21. Dez 2009, 18:49:36 +0100 schrieb Johan 't Hart:
Show 13 quoted lines
> Bertram Scharpf schreef:
>
>>   % 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)

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
-- 
Bertram Scharpf
Stuttgart, Deutschland/Germany
http://www.bertram-scharpf.de

← back to recent threads