# reverting initial commit

10 messages from 2009-03-25 to 2009-03-25. Participants: Pascal Obry, Jacob Helwig, Junio C Hamano, Giuseppe Bilotta, Sverre Rabbelier, Eric Raible.
Thread: https://gitlist.dev/t/18541

## Pascal Obry, 2009-03-25 18:12

Subject: reverting initial commit
Message-ID: <49CA7428.70400@obry.net>
URL: https://gitlist.dev/e/49CA7428.70400%40obry.net

```

Starting a new project I create a new repo and added some files for the
initial revision of the project, something like:

mkdir repo.git
cd repo.git
git init
touch file
git add file
git ci -m "initial revision"

Now one file was not meant to be committed, I wanted to revert this commit:

git reset HEAD^

fatal: ambiguous argument 'HEAD^': unknown revision or path not in the
working tree.
Use '--' to separate paths from revisions

I understand that HEAD^ does not exist, is there a way to do that?

Thanks,
Pascal.

-- 

--|------------------------------------------------------
--| 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

```

## Jacob Helwig, 2009-03-25 18:20

Subject: Re: reverting initial commit
Message-ID: <8c9a060903251120j3e757e94o96b2b77669c16c61@mail.gmail.com>
URL: https://gitlist.dev/e/8c9a060903251120j3e757e94o96b2b77669c16c61%40mail.gmail.com
In-Reply-To: <49CA7428.70400@obry.net>

```
On Wed, Mar 25, 2009 at 11:12, Pascal Obry <pascal@obry.net> wrote:
>
> Starting a new project I create a new repo and added some files for the
> initial revision of the project, something like:
>
> mkdir repo.git
> cd repo.git
> git init
> touch file
> git add file
> git ci -m "initial revision"
>
> Now one file was not meant to be committed, I wanted to revert this commit:
>
> git reset HEAD^
>
> fatal: ambiguous argument 'HEAD^': unknown revision or path not in the
> working tree.
> Use '--' to separate paths from revisions
>
> I understand that HEAD^ does not exist, is there a way to do that?
>
> Thanks,
> Pascal.
>
> --
>
> --|------------------------------------------------------
> --| 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
>
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

You want "git filter-branch".  Probably something like:

git filter-branch --index-filter 'git rm --cached --ignore-unmatched
FILE_TO_REMOVE' -- --all

This will remove FILE_TO_REMOVE from all commits across all branches.

-Jacob

```

## Junio C Hamano, 2009-03-25 18:26

Subject: Re: reverting initial commit
Message-ID: <7v1vsl4fxo.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v1vsl4fxo.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <49CA7428.70400@obry.net>

```
Pascal Obry <pascal@obry.net> writes:

> Starting a new project I create a new repo and added some files for the
> initial revision of the project, something like:
>
> mkdir repo.git
> cd repo.git
> git init
> touch file
> git add file
> git ci -m "initial revision"
>
> Now one file was not meant to be committed, I wanted to revert this commit:

That's not even an revert.  Can't you simply amend it away?

	$ git rm not-this-file
        $ git commit --amend

```

## Jacob Helwig, 2009-03-25 18:33

Subject: Re: reverting initial commit
Message-ID: <8c9a060903251133x33749041oc2a5152097da0ae8@mail.gmail.com>
URL: https://gitlist.dev/e/8c9a060903251133x33749041oc2a5152097da0ae8%40mail.gmail.com
In-Reply-To: <7v1vsl4fxo.fsf@gitster.siamese.dyndns.org>

```
On Wed, Mar 25, 2009 at 11:26, Junio C Hamano <gitster@pobox.com> wrote:
> Pascal Obry <pascal@obry.net> writes:
>
>> Starting a new project I create a new repo and added some files for the
>> initial revision of the project, something like:
>>
>> mkdir repo.git
>> cd repo.git
>> git init
>> touch file
>> git add file
>> git ci -m "initial revision"
>>
>> Now one file was not meant to be committed, I wanted to revert this commit:
>
> That's not even an revert.  Can't you simply amend it away?
>
>        $ git rm not-this-file
>        $ git commit --amend
> --
> To unsubscribe from this list: send the line "unsubscribe git" in
> the body of a message to majordomo@vger.kernel.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
>

This is obviously the easier way.  (Or a rebase --interactive)  I've
just got filter-branch on the brain, because of a git conversion.

```

## Pascal Obry, 2009-03-25 18:36

Subject: Re: reverting initial commit
Message-ID: <49CA799A.6020807@obry.net>
URL: https://gitlist.dev/e/49CA799A.6020807%40obry.net
In-Reply-To: <7v1vsl4fxo.fsf@gitster.siamese.dyndns.org>

```
Junio C Hamano a écrit :
> That's not even an revert.  

Right.

> Can't you simply amend it away?
> 
> 	$ git rm not-this-file
>         $ git commit --amend

Right, I've done that. But the fact that un-committing the initial
commit was not possible seemed strange to me. At least the error message
should be clearer, don't you think?

Thanks.
Pascal.

-- 

--|------------------------------------------------------
--| 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

```

## Junio C Hamano, 2009-03-25 18:40

Subject: Re: reverting initial commit
Message-ID: <7vbprp30p2.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7vbprp30p2.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <49CA799A.6020807@obry.net>

```
Pascal Obry <pascal@obry.net> writes:

> Junio C Hamano a écrit :
>> That's not even an revert.  
>
> Right.
>
>> Can't you simply amend it away?
>> 
>> 	$ git rm not-this-file
>>         $ git commit --amend
>
> Right, I've done that. But the fact that un-committing the initial
> commit was not possible seemed strange to me. At least the error message
> should be clearer, don't you think?

"You said HEAD^ but there is no such thing?  What are you talking about?"

That sounds clear enough to me, but if you have a patch to improve it,
please send it in.

```

## Giuseppe Bilotta, 2009-03-25 19:45

Subject: Re: reverting initial commit
Message-ID: <gqe1kf$pg1$1@ger.gmane.org>
URL: https://gitlist.dev/e/gqe1kf%24pg1%241%40ger.gmane.org
In-Reply-To: <8c9a060903251133x33749041oc2a5152097da0ae8@mail.gmail.com>

```
On Wednesday 25 March 2009 19:33, Jacob Helwig wrote:
> On Wed, Mar 25, 2009 at 11:26, Junio C Hamano <gitster@pobox.com> wrote:
>>
>> That's not even an revert.  Can't you simply amend it away?
>>
>>        $ git rm not-this-file
>>        $ git commit --amend
> 
> This is obviously the easier way.  (Or a rebase --interactive)

Actually, rebase --interactive cannot be used to amend the first commit.
This is something that has hit me a couple of times when I realised, after
the second or third commit, that I needed to fix the first one. I found
the fastest way in this case to be to just format-patch all but the first
commit, reset --hard to the first commit, amend, and git am what I format-
patched.

I wish there was a way to tell rebase -i to go back to the first commit,
inclusive, but the two or three times I've tried hacking at it I never
managed to come to anything useful 8-/

-- 
Giuseppe "Oblomov" Bilotta

```

## Sverre Rabbelier, 2009-03-25 20:40

Subject: Re: reverting initial commit
Message-ID: <fabb9a1e0903251340x637a21dav6e304aa6d2825958@mail.gmail.com>
URL: https://gitlist.dev/e/fabb9a1e0903251340x637a21dav6e304aa6d2825958%40mail.gmail.com
In-Reply-To: <gqe1kf$pg1$1@ger.gmane.org>

```
Heya,

On Wed, Mar 25, 2009 at 20:45, Giuseppe Bilotta
<giuseppe.bilotta@gmail.com> wrote:
> I wish there was a way to tell rebase -i to go back to the first commit,
> inclusive, but the two or three times I've tried hacking at it I never
> managed to come to anything useful 8-/

Wasn't --root added to rebase -i recently?

-- 
Cheers,

Sverre Rabbelier

```

## Eric Raible, 2009-03-25 21:06

Subject: Re: reverting initial commit
Message-ID: <loom.20090325T205905-856@post.gmane.org>
URL: https://gitlist.dev/e/loom.20090325T205905-856%40post.gmane.org
In-Reply-To: <gqe1kf$pg1$1@ger.gmane.org>

```
Giuseppe Bilotta <giuseppe.bilotta <at> gmail.com> writes:

> Actually, rebase --interactive cannot be used to amend the first commit.
> This is something that has hit me a couple of times when I realised, after
> the second or third commit, that I needed to fix the first one. I found
> the fastest way in this case to be to just format-patch all but the first
> commit, reset --hard to the first commit, amend, and git am what I format-
> patched.
> 
> I wish there was a way to tell rebase -i to go back to the first commit,
> inclusive, but the two or three times I've tried hacking at it I never
> managed to come to anything useful 8-/

I like to be able to rebase -i back to the first commit as well,
which is why I generally start off with:

git init && git commit --allow-empty -m'initial commit'

- Eric

```

## Giuseppe Bilotta, 2009-03-25 21:22

Subject: Re: reverting initial commit
Message-ID: <cb7bb73a0903251422u5e57065l80a6b8449c79fcfd@mail.gmail.com>
URL: https://gitlist.dev/e/cb7bb73a0903251422u5e57065l80a6b8449c79fcfd%40mail.gmail.com
In-Reply-To: <fabb9a1e0903251340x637a21dav6e304aa6d2825958@mail.gmail.com>

```
On Wed, Mar 25, 2009 at 9:40 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
> Heya,
>
> On Wed, Mar 25, 2009 at 20:45, Giuseppe Bilotta
> <giuseppe.bilotta@gmail.com> wrote:
>> I wish there was a way to tell rebase -i to go back to the first commit,
>> inclusive, but the two or three times I've tried hacking at it I never
>> managed to come to anything useful 8-/
>
> Wasn't --root added to rebase -i recently?

>From reading the manpage I assumed it could only be used to put the
stuff on top of something else (the --onto requirement). Or did I miss
something along the way?


-- 
Giuseppe "Oblomov" Bilotta

```
