git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: What does git reset do?

From
Jakub Narebski <jnareb@gmail.com>
Date
Feb 2, 2010, 15:30 UTC
Message-ID
<m3vdefac6k.fsf@localhost.localdomain>
In-Reply-To
<ron1-A2A2DE.23475601022010@news.gmane.org>
Ron Garret <ron1@flownet.com> writes:
Show 14 quoted lines
> 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).

Show 10 quoted lines
> 
> 
> [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
Previous: Octavio Alvarez
Message 5 of 5 in “What does git reset do?”
  1. Ron GarretFeb 2, 2010
  2. Octavio AlvarezFeb 2, 2010
  3. Ron GarretFeb 2, 2010
  4. Octavio AlvarezFeb 2, 2010
  5. Jakub NarebskiFeb 2, 2010

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.