* What does git reset do?
@ 2010-02-02 7:47 Ron Garret
2010-02-02 8:01 ` Octavio Alvarez
2010-02-02 15:30 ` Jakub Narebski
0 siblings, 2 replies; 5+ messages in thread
From: Ron Garret @ 2010-02-02 7:47 UTC (permalink / raw)
To: git
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:
[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?
Thanks,
rg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What does git reset do?
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 15:30 ` Jakub Narebski
1 sibling, 1 reply; 5+ messages in thread
From: Octavio Alvarez @ 2010-02-02 8:01 UTC (permalink / raw)
To: Ron Garret, git
On Mon, 01 Feb 2010 23:47:56 -0800, Ron Garret <ron1@flownet.com> wrote:
> The docs say that git-reset:
>
> "Sets the current head to the specified commit..."
... without modifying your working copy if --soft, and modifying your
working copy if --hard.
... and without switching branches (you want git checkout for that).
> 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:
It actually does. HEAD (and br1) now point to [the commit pointed to by]
master. Your working copy was left intact (because of --soft). Compare
with "git checkout".
gitk --all is your friend to better understand this.
Your branch is still br1. It means, if you commit, br1 will advance, (not
master). But, given your git reset, instead of committing over [the commit
pointed to by previous] br1, you will commit over [the commit pointed to
by] master.
Be careful though, you might lose commits with git reset.
> [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?
Sets the current head (and branch, if not detached) to the specified
commit...
--
--
Octavio.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What does git reset do?
2010-02-02 8:01 ` Octavio Alvarez
@ 2010-02-02 8:24 ` Ron Garret
2010-02-02 8:37 ` Octavio Alvarez
0 siblings, 1 reply; 5+ messages in thread
From: Ron Garret @ 2010-02-02 8:24 UTC (permalink / raw)
To: git
In article <op.u7hpv8nd4oyyg1@localhost.localdomain>,
"Octavio Alvarez" <alvarezp@alvarezp.ods.org> wrote:
> > So... what does git reset do?
>
> Sets the current head (and branch, if not detached) to the specified
> commit...
Ah. It's the "and branch" part that I was missing. Thanks!
Hm... maybe "detached head" is not as inappropriate a term as I first
thought. When you checkout a branch, HEAD really is "attached" to the
branch insofar as the branch head gets "dragged along" on commits and
resets. (Have I got that right?)
rg
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What does git reset do?
2010-02-02 8:24 ` Ron Garret
@ 2010-02-02 8:37 ` Octavio Alvarez
0 siblings, 0 replies; 5+ messages in thread
From: Octavio Alvarez @ 2010-02-02 8:37 UTC (permalink / raw)
To: Ron Garret, git
On Tue, 02 Feb 2010 00:24:26 -0800, Ron Garret <ron1@flownet.com> wrote:
> In article <op.u7hpv8nd4oyyg1@localhost.localdomain>,
> "Octavio Alvarez" <alvarezp@alvarezp.ods.org> wrote:
>
>> > So... what does git reset do?
>>
>> Sets the current head (and branch, if not detached) to the specified
>> commit...
>
> Ah. It's the "and branch" part that I was missing. Thanks!
>
> Hm... maybe "detached head" is not as inappropriate a term as I first
> thought. When you checkout a branch, HEAD really is "attached" to the
> branch insofar as the branch head gets "dragged along" on commits and
> resets. (Have I got that right?)
99% right. I'm just not sure if there is such thing as "branch head".
You may compare the branch with a "moving tag", in which case the branch
is just a pointer, so "branch head" would be redundant, and besides "HEAD"
is an already used term. So you may say simply "branch" instead.
But it's easy intuitive to compare it with a bunch of related commits,
each parent of another. And gitk also has a line that says "branch: _____,
______, ______" for each commit.
In any case, it's just a matter of getting the terms to match the
developers'.
--
--
Octavio.
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: What does git reset do?
2010-02-02 7:47 What does git reset do? Ron Garret
2010-02-02 8:01 ` Octavio Alvarez
@ 2010-02-02 15:30 ` Jakub Narebski
1 sibling, 0 replies; 5+ messages in thread
From: Jakub Narebski @ 2010-02-02 15:30 UTC (permalink / raw)
To: Ron Garret; +Cc: git
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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2010-02-02 15:30 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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 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).