{"thread":{"id":"3038","subject":"reverting back both working copy and commits","startedAt":"2006-01-11T16:32:16Z","lastAt":"2006-01-12T10:40:07Z","messageCount":4,"participants":["Bahadir Balban","Andreas Ericsson","Junio C Hamano"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"14483","messageId":"7ac1e90c0601110832u6fc3a3bcwb7e584445610e53f@mail.gmail.com","threadId":"3038","inReplyTo":null,"subject":"reverting back both working copy and commits","fromName":"Bahadir Balban","fromEmail":"bahadir.balban@gmail.com","sentAt":"2006-01-11T16:32:16Z","receivedAt":"2006-01-11T16:32:16Z","isPatch":false,"sender":{"key":"bahadir.balban@gmail.com","avatar":null},"body":"Hi,\n\nI made some commits that later on I wanted to cancel. I did:\n\n% git-branch master-2006-get-rid-of-commits\n\n% git-reset --hard [sha1id]\n\nwhere sha1id is the id of commit I want to revert back to. After this,\ngit-log points at the right commit (the one with [sha1id]) as the last\ncommit made. However, the working copy is left in the original state,\ni.e with the unwanted changes.. How do I also revert the working\nsources into an earlier state.\n\nBecause git-commit says \"nothing to change\" at this stage, git\ncheckout -f does not cure my problem. How do I also revert working\ncopy to earlier commit?\n\nThanks,\nBahadir\n"},{"id":"14486","messageId":"43C55C51.90305@op5.se","threadId":"3038","inReplyTo":"7ac1e90c0601110832u6fc3a3bcwb7e584445610e53f@mail.gmail.com","subject":"Re: reverting back both working copy and commits","fromName":"Andreas Ericsson","fromEmail":"ae@op5.se","sentAt":"2006-01-11T19:28:17Z","receivedAt":"2006-01-11T19:28:17Z","isPatch":false,"sender":{"key":"ae@op5.se","avatar":"https://gravatar.com/avatar/426e89595c75a8f5252dd0c989e5fabe5bcac616e68557427ad9aef6b0ca342a?d=mp&s=160"},"body":"Bahadir Balban wrote:\n> Hi,\n> \n> I made some commits that later on I wanted to cancel. I did:\n> \n> % git-branch master-2006-get-rid-of-commits\n> \n> % git-reset --hard [sha1id]\n> \n> where sha1id is the id of commit I want to revert back to. After this,\n> git-log points at the right commit (the one with [sha1id]) as the last\n> commit made. However, the working copy is left in the original state,\n> i.e with the unwanted changes.. How do I also revert the working\n> sources into an earlier state.\n> \n\nThe branch where you do the reset is the one being reset, so you should \nhave simply done the reset in the original branch without creating a new \none. If you're nervous you're gonna screw up you can do this;\n\ngit checkout <branch-with-unwanted-commit>\ngit tag anchor\ngit reset --hard <commit-ish>\n\nIf you find you've landed on the wrong commit you can undo the change with\n\ngit reset --hard anchor\n\nwhich will restore the branch to wherever you were prior to the first \nreset. Making an anchor tag is useful if you do several resets. You can \nuse ORIG_HEAD to undo a single reset.\n\n-- \nAndreas Ericsson                   andreas.ericsson@op5.se\nOP5 AB                             www.op5.se\nTel: +46 8-230225                  Fax: +46 8-230231\n"},{"id":"14488","messageId":"7vslrutv2h.fsf@assigned-by-dhcp.cox.net","threadId":"3038","inReplyTo":"7ac1e90c0601110832u6fc3a3bcwb7e584445610e53f@mail.gmail.com","subject":"Re: reverting back both working copy and commits","fromName":"Junio C Hamano","fromEmail":"junkio@cox.net","sentAt":"2006-01-11T19:37:26Z","receivedAt":"2006-01-11T19:37:26Z","isPatch":false,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Bahadir Balban <bahadir.balban@gmail.com> writes:\n\n> % git-branch master-2006-get-rid-of-commits\n>\n> % git-reset --hard [sha1id]\n>\n> where sha1id is the id of commit I want to revert back to. After this,\n> git-log points at the right commit (the one with [sha1id]) as the last\n> commit made. However, the working copy is left in the original state,\n> i.e with the unwanted changes.\n\nEh?  That should not happen.\n\nCould you elaborate?\n\n\t$ git diff master-2006-get-rid-of-commits\n\nshould show differences between the wrongly committed state and\nyour working tree.\n\n\t$ git diff --cached HEAD ;# or git diff --cached [sha1id]\n\nshould show *nothing* and\n\n\t$ git diff HEAD ;# or git diff [sha1id]\n\nshould also show nothing.\n\nWhat is different between what I just described \"Thess should\nhappen\" and what actually happens to you?  I use \"git reset\n--hard\" all the time, probably a lot more often than other\npeople, and I'd be surprised if things are not working.\n\nWhat \"git reset --hard\" would leave behind are files in the\nworking tree that you had when you made the wrongly done commit,\nwhich were *not* known to git (i.e. you forgot to \"git add\"\nbefore committing).  Since they are not known to git, \"reset --hard\"\ndoes not touch them.\n"},{"id":"14545","messageId":"7ac1e90c0601120240u3f8d7571g5e5bf52b6d3c4c2a@mail.gmail.com","threadId":"3038","inReplyTo":"7vslrutv2h.fsf@assigned-by-dhcp.cox.net","subject":"Re: reverting back both working copy and commits","fromName":"Bahadir Balban","fromEmail":"bahadir.balban@gmail.com","sentAt":"2006-01-12T10:40:07Z","receivedAt":"2006-01-12T10:40:07Z","isPatch":false,"sender":{"key":"bahadir.balban@gmail.com","avatar":null},"body":"On 1/11/06, Junio C Hamano <junkio@cox.net> wrote:\n> Eh?  That should not happen.\n>\n> Could you elaborate?\n> What \"git reset --hard\" would leave behind are files in the\n> working tree that you had when you made the wrongly done commit,\n> which were *not* known to git (i.e. you forgot to \"git add\"\n> before committing).  Since they are not known to git, \"reset --hard\"\n> does not touch them.\n\nSorry, it's my mistake, I later realised the working tree had been\nupdated correctly.\n\nThanks,\nBahadir\n"}]}