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

Re: cache status after git pull

From
Junio C Hamano <junkio@cox.net>
Date
Aug 25, 2005, 20:26 UTC
Message-ID
<7v4q9dvk4g.fsf@assigned-by-dhcp.cox.net>
In-Reply-To
<200508251608.j7PG8XGq016882@agluck-lia64.sc.intel.com>
tony.luck@intel.com writes:
> Aha ... is this the problem that caught me out last week (when
> I ended up with 10 extra files attached to one of my commits)?
Plausible.
> 1) Updated my "linus" branch:
>
>   $ git checkout linus && git pull linus

I would assume that just after "git checkout linus" before "git pull linus", running "git diff -r linus" would have said nothing.

The second command, "git pull linus", would internally run "git fetch linus". It depends on how your shorthand "linus" is defined, but if it is set to update (either overwrite or fast-forward) the "linus" branch head, then your HEAD pointer would be updated without updating the index and working tree. This is bad because now you are telling git that your working tree is based on updated "linus" branch head, and what you _could_ commit on top of it is the same thing as what old "linus" branch head commit used to have. That's why "git status" output shows the minefield.

If I keep copies of foreign brahches in $GIT_DIR/refs/heads/ somewhere, I never checkout those branches in my working tree. I always stay in my branches to do my work. I may "diff" against them to see where I am. Of course I would "resolve" with them when I feel I am ready.

So, assumes that "linus" short-hand is set up to update $GIT_DIR/refs/heads/linus with the foreign branch head, the above example would have been:

    $ git checkout master && git pull linus
    : examine diffs and be convinced what Linus does is always right.

If my "master" branch is not ready to merge from Linus but I want to get a feel of what is coming, I would instead do:

    : while staying on my master branch
    $ git fetch linus
    $ gitk linus master ;# or git show-branch linus master

and later when my branch is ready, I would merge it into my master:

    : still staying on my master branch
    $ git pull . linus

If you did the pull into your master but it turns out that the merge result is too messy, you could always reset (back to the first example):

    $ git checkout master && git pull linus
    : if merge failed...
    $ git reset --hard master
    $ git checkout master && git pull linus
    : merge succeeds, but I realize that my tree was not quite
    : ready to merge from linus -- going back to pre-merge state
    $ git reset --hard master^1

The rules for updating $GIT_DIR/refs/ when fetch happens have been extended and clarified in 0.99.5 quite a bit.

To set up "linus" short-hand to be updated with "master" branch head from Linus, you would do one of the following:

  * Using old style shorthand
    $ echo >$GIT_DIR/branches/linus \
    http://www.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/
    $ git fetch linus
  * Using new style shorthand
    $ cat >$GIT_DIR/remotes/linus \
    URL: http://www.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/
    Pull: master:linus
    $ git fetch linus
  * From the command line, having either branches/linus or
    remotes/linus from the above two examples:
    $ git fetch linus master:linus

To set up "linus" short-hand _not_ to update any local branch head (i.e. you only use "pull" to update your local branch, which can be named "linus" branch), you would do one of the following:

  * Using old style shorthand
    There is no way to do this using old style shorthand without
    an explicit command line <refspec>.  See the "From the
    command line" example below how to do this.
  * Using new style shorthand
    $ cat >$GIT_DIR/remotes/linus \
    URL: http://www.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6.git/
    Pull: master:
    $ git fetch linus
  * From the command line, having either branches/linus or
    remotes/linus from the above two examples:
    $ git fetch linus master:
Previous: tony.luck@intel.com
Message 2 of 2 in “cache status after git pull”
  1. tony.luck@intel.comAug 25, 2005
  2. Junio C HamanoAug 25, 2005

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.