{"thread":{"id":"21126","subject":"Re: reset doesn't reset a revert?","startedAt":"2009-10-04T12:18:36Z","lastAt":"2009-10-04T18:37:55Z","messageCount":2,"participants":["Adam Brewster","Octavian Râşniţă"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"299131","messageId":"98300251CB1D46A0B635B4495138C3A7@teddy","threadId":"21126","inReplyTo":null,"subject":"reset doesn't reset a revert?","fromName":"Octavian Râşniţă","fromEmail":"orasnita@gmail.com","sentAt":"2009-10-04T12:18:36Z","receivedAt":"2009-10-04T12:18:36Z","isPatch":false,"sender":{"key":"orasnita@gmail.com","avatar":null},"body":"Hi,\n\nUnder Windows XP, using git version 1.6.4.msysgit.0, I have tried:\n\nE:\\lucru\\git\\k>echo foo > file.txt\nE:\\lucru\\git\\k>echo bar >> file.txt\nE:\\lucru\\git\\k>git init\nInitialized empty Git repository in E:/lucru/git/k/.git/\nE:\\lucru\\git\\k>git add .\nwarning: CRLF will be replaced by LF in file.txt.\nE:\\lucru\\git\\k>git commit -a\n[master (root-commit) e969cd5] First commit\nwarning: CRLF will be replaced by LF in file.txt.\n1 files changed, 2 insertions(+), 0 deletions(-)\ncreate mode 100644 file.txt\nE:\\lucru\\git\\k>echo baz >> file.txt\nE:\\lucru\\git\\k>git commit -a\nwarning: CRLF will be replaced by LF in file.txt.\nwarning: CRLF will be replaced by LF in file.txt.\n[master warning: CRLF will be replaced by LF in file.txt.\nfabd2f2] Added baz to file.txt\n1 files changed, 1 insertions(+), 0 deletions(-)\nE:\\lucru\\git\\k>type file.txt\nfoo\nbar\nbaz\n\n#Until here, everything's OK.\n\nE:\\lucru\\git\\k>git  revert HEAD~\nfatal: Cannot revert a root commit\n\n#Does anyone know what does this mean? So I've tried with HEAD^ instead.\n\nE:\\lucru\\git\\k>git  revert HEAD^\nMore?\nMore?\nFinished one revert.\n[master 1beba20] Revert \"Added baz to file.txt\"\n1 files changed, 0 insertions(+), 1 deletions(-)\n\n# What should I respond to the questions More?\n#I've seen that no matter what I type, it adds to the \"HEAD\" and tells that \nthat commit can't be found, so I just pressed enter.\n\nE:\\lucru\\git\\k>git status\n# On branch master\nnothing to commit (working directory clean)\nE:\\lucru\\git\\k>git log --pretty=format:\"%s %h\"\nWARNING: terminal is not fully functional\nRevert \"Added baz to file.txt\" 1beba20\nAdded baz to file.txt fabd2f2\nFirst commit e969cd5\n(END)\n\n#It seems that the revert commit was added successfully.\n\nE:\\lucru\\git\\k>type file.txt\nfoo\nbar\n\n#And it seems that not only the repository was changed, but the working \ndirectory also. Is it correct?\n\n#Well, now let's say I discovered that this new commit was an error and I \nwant to reset it.\n#And I used HEAD^ because HEAD~ didn't work with revert.\n\nE:\\lucru\\git\\k>git reset HEAD^\nMore?\nMore?\nE:\\lucru\\git\\k>git log --pretty=format:\"%s %h\"\nWARNING: terminal is not fully functional\nRevert \"Added baz to file.txt\" 1beba20\nAdded baz to file.txt fabd2f2\nFirst commit e969cd5\n(END)\n\n#Well, git reset didn't reset the latest commit.\n#Does anyone know why or what I am doing wrong?\n\nE:\\lucru\\git\\k>git status\n# On branch master\nnothing to commit (working directory clean)\nE:\\lucru\\git\\k>git reset HEAD~\nfile.txt: locally modified\nE:\\lucru\\git\\k>git log --pretty=format:\"%s %h\"\nWARNING: terminal is not fully functional\nAdded baz to file.txt fabd2f2\nFirst commit e969cd5\n(END)\n\n#This time git reset resetted the latest HEAD.\n#It seems that git reset wants the HEAD~ commit, while git revert wants the \nHEAD^ commit. Do you know why (or can I find an explanation for this \nsomewhere)?\n\nE:\\lucru\\git\\k>type file.txt\nfoo\nbar\n\n#However, git reset modified just the repository and not the working \ndirectory.\n\nI added the line baz in the file file.txt, commited this change and then \nreverted to the previous commit. This has also deleted the line \"baz\" from \nthe file.\nThen I resetted the last commit (the revert), however the line \"baz\" didn't \nappear in the file.\n\nIs this something normal I should expect, or I am doing something wrong?\n\nThank you very much.\n\nOctavian\n\n"},{"id":"124203","messageId":"c376da900910041137v6766de4u1419a8209751dcb9@mail.gmail.com","threadId":"21126","inReplyTo":"98300251CB1D46A0B635B4495138C3A7@teddy","subject":"Re: reset doesn't reset a revert?","fromName":"Adam Brewster","fromEmail":"adambrewster@gmail.com","sentAt":"2009-10-04T18:37:55Z","receivedAt":"2009-10-04T18:37:55Z","isPatch":false,"sender":{"key":"adambrewster@gmail.com","avatar":"https://avatars.githubusercontent.com/u/223816?v=4"},"body":">\n> E:\\lucru\\git\\k>git  revert HEAD~\n> fatal: Cannot revert a root commit\n>\n> #Does anyone know what does this mean? So I've tried with HEAD^ instead.\n>\n\nGit revert isn't like svn revert.  GIt revert creates a new commit off\nof the HEAD that introduces a change that's the opposite of the change\nintroduced in the commit you specify.  The first commit in a\nrepository doesn't introduce any change because there's no previous\ncommit.\n\nLike it says, you can't revert the first commit in the history.\n\n> E:\\lucru\\git\\k>git  revert HEAD^\n> More?\n> More?\n> Finished one revert.\n> [master 1beba20] Revert \"Added baz to file.txt\"\n> 1 files changed, 0 insertions(+), 1 deletions(-)\n>\n> # What should I respond to the questions More?\n> #I've seen that no matter what I type, it adds to the \"HEAD\" and tells that\n> that commit can't be found, so I just pressed enter.\n>\n>\n\nIt seems the caret is special to the windows command prompt.  I don't\nknow what it does, but a line of nonsense that ends in ^ causes the\nMore? More? response you described.  Try quoting the argument so your\nshell doesn't mangle it.\n\n>\n> #And it seems that not only the repository was changed, but the working\n> directory also. Is it correct?\n>\n\nThat's how revert usually works,\n\n> #Well, now let's say I discovered that this new commit was an error and I\n> want to reset it.\n> #And I used HEAD^ because HEAD~ didn't work with revert.\n>\n> E:\\lucru\\git\\k>git reset HEAD^\n> More?\n> More?\n> E:\\lucru\\git\\k>git log --pretty=format:\"%s %h\"\n> WARNING: terminal is not fully functional\n> Revert \"Added baz to file.txt\" 1beba20\n> Added baz to file.txt fabd2f2\n> First commit e969cd5\n> (END)\n>\n> #Well, git reset didn't reset the latest commit.\n> #Does anyone know why or what I am doing wrong?\n>\n\nI don't know what the ^ means, but I'm guessing it's not getting\npassed to git.  I'm guessing what you really did is `git reset HEAD`\nwhich clears the index but doesn't undo any commits.\n\n> E:\\lucru\\git\\k>git status\n> # On branch master\n> nothing to commit (working directory clean)\n> E:\\lucru\\git\\k>git reset HEAD~\n> file.txt: locally modified\n> E:\\lucru\\git\\k>git log --pretty=format:\"%s %h\"\n> WARNING: terminal is not fully functional\n> Added baz to file.txt fabd2f2\n> First commit e969cd5\n> (END)\n>\n> #This time git reset resetted the latest HEAD.\n> #It seems that git reset wants the HEAD~ commit, while git revert wants the\n> HEAD^ commit. Do you know why (or can I find an explanation for this\n> somewhere)?\n>\n\nWindows' command shell sucks.  I don't use it.  I don't recommend it.\nTry Cygwin.  Or PuTTYcyg.\n\n> E:\\lucru\\git\\k>type file.txt\n> foo\n> bar\n>\n> #However, git reset modified just the repository and not the working\n> directory.\n>\n\ngit reset has three modes.  --hard, --soft, and --mixed.  If you\nweren't using windows' shell you could type man git-reset to find out\nabout them.  Try googling git reset.  Basically git reset doesn't mess\nwith your working copy files unless you ask it to.\n\n> I added the line baz in the file file.txt, commited this change and then\n> reverted to the previous commit. This has also deleted the line \"baz\" from\n> the file.\n> Then I resetted the last commit (the revert), however the line \"baz\" didn't\n> appear in the file.\n>\n\nReset and revert are very different commands.  Make sure you\nunderstand the difference.\n\nAdam\n"}]}