{"thread":{"id":"22479","subject":"What does git reset do?","startedAt":"2010-02-02T07:47:56Z","lastAt":"2010-02-02T15:30:11Z","messageCount":5,"participants":["Ron Garret","Octavio Alvarez","Jakub Narebski"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"133327","messageId":"ron1-A2A2DE.23475601022010@news.gmane.org","threadId":"22479","inReplyTo":null,"subject":"What does git reset do?","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-02T07:47:56Z","receivedAt":"2010-02-02T07:47:56Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"The docs say that git-reset:\n\n\"Sets the current head to the specified commit...\"\n\nSo I tried this:\n\n\n[ron@mickey:~/devel/gittest]$ git branch\n* br1\n  master\n[ron@mickey:~/devel/gittest]$ git reset --soft master\n\n\n...expecting HEAD to now point to master.  But it doesn't:\n\n\n[ron@mickey:~/devel/gittest]$ git branch\n* br1\n  master\n[ron@mickey:~/devel/gittest]$ more .git/HEAD \nref: refs/heads/br1\n\n\nSo... what does git reset do?\n\nThanks,\nrg\n"},{"id":"133330","messageId":"op.u7hpv8nd4oyyg1@localhost.localdomain","threadId":"22479","inReplyTo":"ron1-A2A2DE.23475601022010@news.gmane.org","subject":"Re: What does git reset do?","fromName":"Octavio Alvarez","fromEmail":"alvarezp@alvarezp.ods.org","sentAt":"2010-02-02T08:01:40Z","receivedAt":"2010-02-02T08:01:40Z","isPatch":false,"sender":{"key":"alvarezp@alvarezp.ods.org","avatar":null},"body":"On Mon, 01 Feb 2010 23:47:56 -0800, Ron Garret <ron1@flownet.com> wrote:\n\n> The docs say that git-reset:\n>\n> \"Sets the current head to the specified commit...\"\n\n... without modifying your working copy if --soft, and modifying your  \nworking copy if --hard.\n\n... and without switching branches (you want git checkout for that).\n\n> So I tried this:\n>\n> [ron@mickey:~/devel/gittest]$ git branch\n> * br1\n>   master\n> [ron@mickey:~/devel/gittest]$ git reset --soft master\n>\n>\n> ...expecting HEAD to now point to master.  But it doesn't:\n\nIt actually does. HEAD (and br1) now point to [the commit pointed to by]  \nmaster. Your working copy was left intact (because of --soft). Compare  \nwith \"git checkout\".\n\ngitk --all is your friend to better understand this.\n\nYour branch is still br1. It means, if you commit, br1 will advance, (not  \nmaster). But, given your git reset, instead of committing over [the commit  \npointed to by previous] br1, you will commit over [the commit pointed to  \nby] master.\n\nBe careful though, you might lose commits with git reset.\n\n> [ron@mickey:~/devel/gittest]$ git branch\n> * br1\n>   master\n> [ron@mickey:~/devel/gittest]$ more .git/HEAD\n> ref: refs/heads/br1\n>\n>\n> So... what does git reset do?\n\nSets the current head (and branch, if not detached) to the specified  \ncommit...\n\n-- \n--\nOctavio.\n"},{"id":"133336","messageId":"ron1-2B8474.00242602022010@news.gmane.org","threadId":"22479","inReplyTo":"op.u7hpv8nd4oyyg1@localhost.localdomain","subject":"Re: What does git reset do?","fromName":"Ron Garret","fromEmail":"ron1@flownet.com","sentAt":"2010-02-02T08:24:26Z","receivedAt":"2010-02-02T08:24:26Z","isPatch":false,"sender":{"key":"ron1@flownet.com","avatar":null},"body":"In article <op.u7hpv8nd4oyyg1@localhost.localdomain>,\n \"Octavio Alvarez\" <alvarezp@alvarezp.ods.org> wrote:\n\n> > So... what does git reset do?\n> \n> Sets the current head (and branch, if not detached) to the specified  \n> commit...\n\nAh.  It's the \"and branch\" part that I was missing.  Thanks!\n\nHm... maybe \"detached head\" is not as inappropriate a term as I first \nthought.  When you checkout a branch, HEAD really is \"attached\" to the \nbranch insofar as the branch head gets \"dragged along\" on commits and \nresets.  (Have I got that right?)\n\nrg\n"},{"id":"133338","messageId":"op.u7hrj8vb4oyyg1@localhost.localdomain","threadId":"22479","inReplyTo":"ron1-2B8474.00242602022010@news.gmane.org","subject":"Re: What does git reset do?","fromName":"Octavio Alvarez","fromEmail":"alvarezp@alvarezp.ods.org","sentAt":"2010-02-02T08:37:10Z","receivedAt":"2010-02-02T08:37:10Z","isPatch":false,"sender":{"key":"alvarezp@alvarezp.ods.org","avatar":null},"body":"On Tue, 02 Feb 2010 00:24:26 -0800, Ron Garret <ron1@flownet.com> wrote:\n\n> In article <op.u7hpv8nd4oyyg1@localhost.localdomain>,\n>  \"Octavio Alvarez\" <alvarezp@alvarezp.ods.org> wrote:\n>\n>> > So... what does git reset do?\n>>\n>> Sets the current head (and branch, if not detached) to the specified\n>> commit...\n>\n> Ah.  It's the \"and branch\" part that I was missing.  Thanks!\n>\n> Hm... maybe \"detached head\" is not as inappropriate a term as I first\n> thought.  When you checkout a branch, HEAD really is \"attached\" to the\n> branch insofar as the branch head gets \"dragged along\" on commits and\n> resets.  (Have I got that right?)\n\n99% right. I'm just not sure if there is such thing as \"branch head\".\n\nYou may compare the branch with a \"moving tag\", in which case the branch  \nis just a pointer, so \"branch head\" would be redundant, and besides \"HEAD\"  \nis an already used term. So you may say simply \"branch\" instead.\n\nBut it's easy intuitive to compare it with a bunch of related commits,  \neach parent of another. And gitk also has a line that says \"branch: _____,  \n______, ______\" for each commit.\n\nIn any case, it's just a matter of getting the terms to match the  \ndevelopers'.\n\n\n-- \n--\nOctavio.\n"},{"id":"133361","messageId":"m3vdefac6k.fsf@localhost.localdomain","threadId":"22479","inReplyTo":"ron1-A2A2DE.23475601022010@news.gmane.org","subject":"Re: What does git reset do?","fromName":"Jakub Narebski","fromEmail":"jnareb@gmail.com","sentAt":"2010-02-02T15:30:11Z","receivedAt":"2010-02-02T15:30:11Z","isPatch":false,"sender":{"key":"jnareb@gmail.com","avatar":"https://avatars.githubusercontent.com/u/2706?v=4"},"body":"Ron Garret <ron1@flownet.com> writes:\n\n> The docs say that git-reset:\n> \n> \"Sets the current head to the specified commit...\"\n> \n> So I tried this:\n> \n> \n> [ron@mickey:~/devel/gittest]$ git branch\n> * br1\n>   master\n> [ron@mickey:~/devel/gittest]$ git reset --soft master\n> \n> \n> ...expecting HEAD to now point to master.  But it doesn't:\n\nFirst, 'current head' is what HEAD points to, which means 'br1'\nbranch.\n\nSecond, \"git reset --soft master\" sets 'br1' branch to _commit_\n'master' (commit referenced by 'master' branch).\n\n> \n> \n> [ron@mickey:~/devel/gittest]$ git branch\n> * br1\n>   master\n> [ron@mickey:~/devel/gittest]$ more .git/HEAD \n> ref: refs/heads/br1\n> \n> \n> So... what does git reset do?\n\nLet's assume that we have the following situation:\n\n\n                /-*        <-- branch_A\n               /\n  *---*---*---*---*---*    <-- branch_B  <--- HEAD\n\n1. $ git checkout branch_A\n\nsets HEAD to branch_A, and sets index and working directory:\n\n                /-*        <-- branch_A  <--- HEAD\n               /\n  *---*---*---*---*---*    <-- branch_B\n\n\n2. $ git reset --hard HEAD\n\nsets current branch to commit pointer by branch_A (--soft, --mixed,\n--hard), and sets index (--hard and --mixed) and working directory\n(--hard):\n\n                   /---------- branch_B  <--- HEAD\n                  v\n\n                /-*        <-- branch_A\n               /\n  *---*---*---*---*---*    \n\n..................................................\n\nLet's assume that we have the following situation:\n\n\n  *---*---*---a---b---c    <-- branch_A  <--- HEAD\n              ^\n              |\n            v1.0 (tag)\n\n\n3. $ git checkout v1.0\n\ndetaches HEAD:\n\n\n                /-b---c    <-- branch_A\n               /\n  *---*---*---a            <--- HEAD\n              ^\n              |\n            v1.0 (tag)\n\n\n4. $ git reset --hard v1.0\n\nrewinds current branch:\n\n                /-b---c    \n               /\n  *---*---*---a            <-- branch_A <--- HEAD\n              ^\n              |\n            v1.0 (tag)\n\nNote that commit 'c' might be referenced only by ORIG_HEAD, HEAD@{1}\n(reflog for HEAD), and branch_A@{1} (reflog for branch_A); if it is\nthe case commits 'b' and 'c' would get garbage-collected and removed\neventually.\n\nHTH\n-- \nJakub Narebski\nPoland\nShadeHawk on #git\n"}]}