Skip to contentSkip to conversation

reverting initial commit

DISCUSSION Pascal Obry 6 participants 10 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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.

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
#1 lore raw
Quoted 11 lines · Pascal Obry

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
#2 lore raw
Quoted 1 line · Junio C Hamano

That's not even an revert.

Right.

Quoted 4 lines

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.

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
#3 lore raw
Quoted 5 lines · Pascal Obry
Quoted 1 line · Junio C Hamano

That's not even an revert.

Right.

Quoted 8 lines
Quoted 4 lines

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.

#4 lore raw
In reply to Junio C Hamano
Quoted 14 lines · Junio C Hamano
Quoted 11 lines · Pascal Obry

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:

Quoted 9 lines

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 [email protected]
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.

#5 lore raw
Quoted 8 lines · Jacob Helwig
Quoted 5 lines · Junio C Hamano

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

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#6 lore raw

Heya,

Quoted 3 lines · Giuseppe Bilotta

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?

Signature · 3 lines
Cheers,

Sverre Rabbelier
#7 lore raw
Quoted 11 lines · Sverre Rabbelier

Heya,

Quoted 3 lines · Giuseppe Bilotta

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?

Signature · 1 line
Giuseppe "Oblomov" Bilotta
#8 lore raw
In reply to Giuseppe Bilotta
Quoted 10 lines · 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

#9 lore raw
In reply to Pascal Obry
Quoted 35 lines · Pascal Obry

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
Quoted 5 lines

--
To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to [email protected]
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