threads / discuss / 18541

reverting initial commit

Subject: reverting initial commit

## tl;dr

10 messages between Mar 25, 2009 and Mar 25, 2009.

replies: 9people: 6as markdown or json

Pascal Obry· Mar 25, 2009, 18:12 UTC · lore

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· Mar 25, 2009, 18:20 UTC · re: Pascal Obry · lore

Re: reverting initial commit

On Wed, Mar 25, 2009 at 11:12, Pascal Obry <pascal@obry.net> wrote:
Show 40 quoted lines
>
> 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· Mar 25, 2009, 18:26 UTC · re: Pascal Obry · lore

Re: reverting initial commit

Pascal Obry <pascal@obry.net> writes:
Show 11 quoted lines
> 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· Mar 25, 2009, 18:33 UTC · re: Junio C Hamano · lore

Re: reverting initial commit

On Wed, Mar 25, 2009 at 11:26, Junio C Hamano <gitster@pobox.com> wrote:
Show 23 quoted lines
> 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.

Giuseppe Bilotta· Mar 25, 2009, 19:45 UTC · re: Jacob Helwig · lore

Re: reverting initial commit

On Wednesday 25 March 2009 19:33, Jacob Helwig wrote:
Show 8 quoted lines
> 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· Mar 25, 2009, 20:40 UTC · re: Giuseppe Bilotta · lore

Re: reverting initial commit

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
Giuseppe Bilotta· Mar 25, 2009, 21:22 UTC · re: Sverre Rabbelier · lore

Re: reverting initial commit

On Wed, Mar 25, 2009 at 9:40 PM, Sverre Rabbelier <srabbelier@gmail.com> wrote:
Show 9 quoted lines
> 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
Eric Raible· Mar 25, 2009, 21:06 UTC · re: Giuseppe Bilotta · lore

Re: reverting initial commit

Giuseppe Bilotta <giuseppe.bilotta <at> gmail.com> writes:
Show 10 quoted lines
> 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
Pascal Obry· Mar 25, 2009, 18:36 UTC · re: Junio C Hamano · lore

Re: reverting initial commit

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· Mar 25, 2009, 18:40 UTC · re: Pascal Obry · lore

Re: reverting initial commit

Pascal Obry <pascal@obry.net> writes:
Show 13 quoted lines
> 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.

← back to recent threads