From: Jakub Narebski <jnareb@gmail.com>
To: Ron Garret <ron1@flownet.com>
Cc: git@vger.kernel.org
Subject: Re: What does git reset do?
Date: Tue, 02 Feb 2010 07:30:11 -0800 (PST) [thread overview]
Message-ID: <m3vdefac6k.fsf@localhost.localdomain> (raw)
In-Reply-To: <ron1-A2A2DE.23475601022010@news.gmane.org>
Ron Garret <ron1@flownet.com> writes:
> The docs say that git-reset:
>
> "Sets the current head to the specified commit..."
>
> So I tried this:
>
>
> [ron@mickey:~/devel/gittest]$ git branch
> * br1
> master
> [ron@mickey:~/devel/gittest]$ git reset --soft master
>
>
> ...expecting HEAD to now point to master. But it doesn't:
First, 'current head' is what HEAD points to, which means 'br1'
branch.
Second, "git reset --soft master" sets 'br1' branch to _commit_
'master' (commit referenced by 'master' branch).
>
>
> [ron@mickey:~/devel/gittest]$ git branch
> * br1
> master
> [ron@mickey:~/devel/gittest]$ more .git/HEAD
> ref: refs/heads/br1
>
>
> So... what does git reset do?
Let's assume that we have the following situation:
/-* <-- branch_A
/
*---*---*---*---*---* <-- branch_B <--- HEAD
1. $ git checkout branch_A
sets HEAD to branch_A, and sets index and working directory:
/-* <-- branch_A <--- HEAD
/
*---*---*---*---*---* <-- branch_B
2. $ git reset --hard HEAD
sets current branch to commit pointer by branch_A (--soft, --mixed,
--hard), and sets index (--hard and --mixed) and working directory
(--hard):
/---------- branch_B <--- HEAD
v
/-* <-- branch_A
/
*---*---*---*---*---*
..................................................
Let's assume that we have the following situation:
*---*---*---a---b---c <-- branch_A <--- HEAD
^
|
v1.0 (tag)
3. $ git checkout v1.0
detaches HEAD:
/-b---c <-- branch_A
/
*---*---*---a <--- HEAD
^
|
v1.0 (tag)
4. $ git reset --hard v1.0
rewinds current branch:
/-b---c
/
*---*---*---a <-- branch_A <--- HEAD
^
|
v1.0 (tag)
Note that commit 'c' might be referenced only by ORIG_HEAD, HEAD@{1}
(reflog for HEAD), and branch_A@{1} (reflog for branch_A); if it is
the case commits 'b' and 'c' would get garbage-collected and removed
eventually.
HTH
--
Jakub Narebski
Poland
ShadeHawk on #git
prev parent reply other threads:[~2010-02-02 15:30 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-02-02 7:47 What does git reset do? Ron Garret
2010-02-02 8:01 ` Octavio Alvarez
2010-02-02 8:24 ` Ron Garret
2010-02-02 8:37 ` Octavio Alvarez
2010-02-02 15:30 ` Jakub Narebski [this message]
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=m3vdefac6k.fsf@localhost.localdomain \
--to=jnareb@gmail.com \
--cc=git@vger.kernel.org \
--cc=ron1@flownet.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).