git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* reset doesn't reset a revert?
@ 2009-10-04 12:18 Octavian Râşniţă
  2009-10-04 18:37 ` Adam Brewster
  0 siblings, 1 reply; 2+ messages in thread
From: Octavian Râşniţă @ 2009-10-04 12:18 UTC (permalink / raw)
  To: git

Hi,

Under Windows XP, using git version 1.6.4.msysgit.0, I have tried:

E:\lucru\git\k>echo foo > file.txt
E:\lucru\git\k>echo bar >> file.txt
E:\lucru\git\k>git init
Initialized empty Git repository in E:/lucru/git/k/.git/
E:\lucru\git\k>git add .
warning: CRLF will be replaced by LF in file.txt.
E:\lucru\git\k>git commit -a
[master (root-commit) e969cd5] First commit
warning: CRLF will be replaced by LF in file.txt.
1 files changed, 2 insertions(+), 0 deletions(-)
create mode 100644 file.txt
E:\lucru\git\k>echo baz >> file.txt
E:\lucru\git\k>git commit -a
warning: CRLF will be replaced by LF in file.txt.
warning: CRLF will be replaced by LF in file.txt.
[master warning: CRLF will be replaced by LF in file.txt.
fabd2f2] Added baz to file.txt
1 files changed, 1 insertions(+), 0 deletions(-)
E:\lucru\git\k>type file.txt
foo
bar
baz

#Until here, everything's OK.

E:\lucru\git\k>git  revert HEAD~
fatal: Cannot revert a root commit

#Does anyone know what does this mean? So I've tried with HEAD^ instead.

E:\lucru\git\k>git  revert HEAD^
More?
More?
Finished one revert.
[master 1beba20] Revert "Added baz to file.txt"
1 files changed, 0 insertions(+), 1 deletions(-)

# What should I respond to the questions More?
#I've seen that no matter what I type, it adds to the "HEAD" and tells that 
that commit can't be found, so I just pressed enter.

E:\lucru\git\k>git status
# On branch master
nothing to commit (working directory clean)
E:\lucru\git\k>git log --pretty=format:"%s %h"
WARNING: terminal is not fully functional
Revert "Added baz to file.txt" 1beba20
Added baz to file.txt fabd2f2
First commit e969cd5
(END)

#It seems that the revert commit was added successfully.

E:\lucru\git\k>type file.txt
foo
bar

#And it seems that not only the repository was changed, but the working 
directory also. Is it correct?

#Well, now let's say I discovered that this new commit was an error and I 
want to reset it.
#And I used HEAD^ because HEAD~ didn't work with revert.

E:\lucru\git\k>git reset HEAD^
More?
More?
E:\lucru\git\k>git log --pretty=format:"%s %h"
WARNING: terminal is not fully functional
Revert "Added baz to file.txt" 1beba20
Added baz to file.txt fabd2f2
First commit e969cd5
(END)

#Well, git reset didn't reset the latest commit.
#Does anyone know why or what I am doing wrong?

E:\lucru\git\k>git status
# On branch master
nothing to commit (working directory clean)
E:\lucru\git\k>git reset HEAD~
file.txt: locally modified
E:\lucru\git\k>git log --pretty=format:"%s %h"
WARNING: terminal is not fully functional
Added baz to file.txt fabd2f2
First commit e969cd5
(END)

#This time git reset resetted the latest HEAD.
#It seems that git reset wants the HEAD~ commit, while git revert wants the 
HEAD^ commit. Do you know why (or can I find an explanation for this 
somewhere)?

E:\lucru\git\k>type file.txt
foo
bar

#However, git reset modified just the repository and not the working 
directory.

I added the line baz in the file file.txt, commited this change and then 
reverted to the previous commit. This has also deleted the line "baz" from 
the file.
Then I resetted the last commit (the revert), however the line "baz" didn't 
appear in the file.

Is this something normal I should expect, or I am doing something wrong?

Thank you very much.

Octavian


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: reset doesn't reset a revert?
  2009-10-04 12:18 reset doesn't reset a revert? Octavian Râşniţă
@ 2009-10-04 18:37 ` Adam Brewster
  0 siblings, 0 replies; 2+ messages in thread
From: Adam Brewster @ 2009-10-04 18:37 UTC (permalink / raw)
  To: Octavian Râşniţă; +Cc: git

>
> E:\lucru\git\k>git  revert HEAD~
> fatal: Cannot revert a root commit
>
> #Does anyone know what does this mean? So I've tried with HEAD^ instead.
>

Git revert isn't like svn revert.  GIt revert creates a new commit off
of the HEAD that introduces a change that's the opposite of the change
introduced in the commit you specify.  The first commit in a
repository doesn't introduce any change because there's no previous
commit.

Like it says, you can't revert the first commit in the history.

> E:\lucru\git\k>git  revert HEAD^
> More?
> More?
> Finished one revert.
> [master 1beba20] Revert "Added baz to file.txt"
> 1 files changed, 0 insertions(+), 1 deletions(-)
>
> # What should I respond to the questions More?
> #I've seen that no matter what I type, it adds to the "HEAD" and tells that
> that commit can't be found, so I just pressed enter.
>
>

It seems the caret is special to the windows command prompt.  I don't
know what it does, but a line of nonsense that ends in ^ causes the
More? More? response you described.  Try quoting the argument so your
shell doesn't mangle it.

>
> #And it seems that not only the repository was changed, but the working
> directory also. Is it correct?
>

That's how revert usually works,

> #Well, now let's say I discovered that this new commit was an error and I
> want to reset it.
> #And I used HEAD^ because HEAD~ didn't work with revert.
>
> E:\lucru\git\k>git reset HEAD^
> More?
> More?
> E:\lucru\git\k>git log --pretty=format:"%s %h"
> WARNING: terminal is not fully functional
> Revert "Added baz to file.txt" 1beba20
> Added baz to file.txt fabd2f2
> First commit e969cd5
> (END)
>
> #Well, git reset didn't reset the latest commit.
> #Does anyone know why or what I am doing wrong?
>

I don't know what the ^ means, but I'm guessing it's not getting
passed to git.  I'm guessing what you really did is `git reset HEAD`
which clears the index but doesn't undo any commits.

> E:\lucru\git\k>git status
> # On branch master
> nothing to commit (working directory clean)
> E:\lucru\git\k>git reset HEAD~
> file.txt: locally modified
> E:\lucru\git\k>git log --pretty=format:"%s %h"
> WARNING: terminal is not fully functional
> Added baz to file.txt fabd2f2
> First commit e969cd5
> (END)
>
> #This time git reset resetted the latest HEAD.
> #It seems that git reset wants the HEAD~ commit, while git revert wants the
> HEAD^ commit. Do you know why (or can I find an explanation for this
> somewhere)?
>

Windows' command shell sucks.  I don't use it.  I don't recommend it.
Try Cygwin.  Or PuTTYcyg.

> E:\lucru\git\k>type file.txt
> foo
> bar
>
> #However, git reset modified just the repository and not the working
> directory.
>

git reset has three modes.  --hard, --soft, and --mixed.  If you
weren't using windows' shell you could type man git-reset to find out
about them.  Try googling git reset.  Basically git reset doesn't mess
with your working copy files unless you ask it to.

> I added the line baz in the file file.txt, commited this change and then
> reverted to the previous commit. This has also deleted the line "baz" from
> the file.
> Then I resetted the last commit (the revert), however the line "baz" didn't
> appear in the file.
>

Reset and revert are very different commands.  Make sure you
understand the difference.

Adam

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2009-10-04 18:39 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2009-10-04 12:18 reset doesn't reset a revert? Octavian Râşniţă
2009-10-04 18:37 ` Adam Brewster

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).