# Delete a commit

8 messages from 2009-12-19 to 2009-12-21. Participants: Bertram Scharpf, Johan 't Hart, James P. Howard, II, Pascal Obry, Andreas Schwab.
Thread: https://gitlist.dev/t/21994

## Bertram Scharpf, 2009-12-19 23:39

Subject: Delete a commit
Message-ID: <20091219233957.GC29111@marge.bs.l>
URL: https://gitlist.dev/e/20091219233957.GC29111%40marge.bs.l

```
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, 2009-12-19 23:43

Subject: Re: Delete a commit
Message-ID: <20091219234327.GA45385@byzantine.jameshoward.us>
URL: https://gitlist.dev/e/20091219234327.GA45385%40byzantine.jameshoward.us
In-Reply-To: <20091219233957.GC29111@marge.bs.l>

```
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, 2009-12-20 00:06

Subject: Re: Delete a commit
Message-ID: <hgjpqu$dos$1@ger.gmane.org>
URL: https://gitlist.dev/e/hgjpqu%24dos%241%40ger.gmane.org
In-Reply-To: <20091219233957.GC29111@marge.bs.l>

```
Bertram Scharpf schreef:
> 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.

> 
> Thanks in advance.
> 
> Bertram
> 
> 

```

## Bertram Scharpf, 2009-12-20 00:43

Subject: Re: Delete a commit
Message-ID: <20091220004340.GA30440@marge.bs.l>
URL: https://gitlist.dev/e/20091220004340.GA30440%40marge.bs.l
In-Reply-To: <hgjpqu$dos$1@ger.gmane.org>

```
Hi,

Am Sonntag, 20. Dez 2009, 01:06:46 +0100 schrieb Johan 't Hart:
> 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, 2009-12-20 08:37

Subject: Re: Delete a commit
Message-ID: <4B2DE24A.7040402@obry.net>
URL: https://gitlist.dev/e/4B2DE24A.7040402%40obry.net
In-Reply-To: <20091220004340.GA30440@marge.bs.l>

```
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, 2009-12-21 17:49

Subject: Re: Delete a commit
Message-ID: <hgocfi$pge$1@ger.gmane.org>
URL: https://gitlist.dev/e/hgocfi%24pge%241%40ger.gmane.org
In-Reply-To: <20091220004340.GA30440@marge.bs.l>

```
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, 2009-12-21 18:17

Subject: Re: Delete a commit
Message-ID: <m2bphsdwds.fsf@igel.home>
URL: https://gitlist.dev/e/m2bphsdwds.fsf%40igel.home
In-Reply-To: <hgocfi$pge$1@ger.gmane.org>

```
Johan 't Hart <johanthart@gmail.com> writes:

> 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, 2009-12-21 21:01

Subject: Re: Delete a commit
Message-ID: <20091221210137.GA17695@marge.bs.l>
URL: https://gitlist.dev/e/20091221210137.GA17695%40marge.bs.l
In-Reply-To: <hgocfi$pge$1@ger.gmane.org>

```
Hi,

Am Montag, 21. Dez 2009, 18:49:36 +0100 schrieb Johan 't Hart:
> 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

```
