# git-checkout sometimes silently fails

10 messages from 2008-05-06 to 2008-05-07. Participants: Andrew Morton, Alex Riesen, Jeff King, Junio C Hamano, Björn Steinbrink, Johannes Sixt, J. Bruce Fields.
Thread: https://gitlist.dev/t/13402

## Andrew Morton, 2008-05-06 19:22

Subject: git-checkout sometimes silently fails
Message-ID: <20080506122256.04ca7d77.akpm@linux-foundation.org>
URL: https://gitlist.dev/e/20080506122256.04ca7d77.akpm%40linux-foundation.org

```

I've had this happen before and I don't know what to do to make it stop. 
Usually sufficient fiddling will prevent it from happening.


y:/usr/src/git26> cat .git/branches/linux-next 
git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git

y:/usr/src/git26> git-checkout master
Switched to branch "master"
y:/usr/src/git26> cat kernel/*.c|sum
34439  2057
y:/usr/src/git26> git-checkout linux-next
Switched to branch "linux-next"
y:/usr/src/git26> cat kernel/*.c|sum     
34439  2057
y:/usr/src/git26> git-checkout origin 
Note: moving to "origin" which isn't a local branch
If you want to create a new branch from this checkout, you may do so
(now or later) by using -b with the checkout command again. Example:
  git checkout -b <new_branch_name>
HEAD is now at 5717922... Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
y:/usr/src/git26> cat kernel/*.c|sum          
34439  2057


y:/usr/src/git26> git --version
git version 1.5.5.rc1

help?

```

## Alex Riesen, 2008-05-06 21:50

Subject: Re: git-checkout sometimes silently fails
Message-ID: <20080506215049.GC4647@steel.home>
URL: https://gitlist.dev/e/20080506215049.GC4647%40steel.home
In-Reply-To: <20080506122256.04ca7d77.akpm@linux-foundation.org>

```
Andrew Morton, Tue, May 06, 2008 21:22:56 +0200:
> 
> I've had this happen before and I don't know what to do to make it stop. 
> Usually sufficient fiddling will prevent it from happening.
> 
> 
> y:/usr/src/git26> cat .git/branches/linux-next 
> git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git
> 
> y:/usr/src/git26> git-checkout master
> Switched to branch "master"
> y:/usr/src/git26> cat kernel/*.c|sum
> 34439  2057
> y:/usr/src/git26> git-checkout linux-next
> Switched to branch "linux-next"
> y:/usr/src/git26> cat kernel/*.c|sum     
> 34439  2057

This is not a good indication of a failed checkout (they could point
to the same commit, for one). Try "gitk master...linux-next" (or "git
log master..linux-next", "git diff master linux-next")

> y:/usr/src/git26> git-checkout origin 
> Note: moving to "origin" which isn't a local branch
> If you want to create a new branch from this checkout, you may do so
> (now or later) by using -b with the checkout command again. Example:
>   git checkout -b <new_branch_name>
> HEAD is now at 5717922... Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb

This is not an error. The commit was checked out (and HEAD was
"detached").

> y:/usr/src/git26> cat kernel/*.c|sum          
> 34439  2057

Again, it is no indication nothing happened. "gitk HEAD...linux-next"

> y:/usr/src/git26> git --version
> git version 1.5.5.rc1
> 
> help?

Look at "git branch -av" (it shows both local and remote branches and
commits they point to). Maybe it will give you a hint. "gitk --all" is
interesting too, seldom though (it becomes very confusing very fast if
you have many branches with complicated history each).

```

## Andrew Morton, 2008-05-07 00:10

Subject: Re: git-checkout sometimes silently fails
Message-ID: <20080506171052.340d643e.akpm@linux-foundation.org>
URL: https://gitlist.dev/e/20080506171052.340d643e.akpm%40linux-foundation.org
In-Reply-To: <20080506215049.GC4647@steel.home>

```
On Tue, 6 May 2008 23:50:49 +0200 Alex Riesen <raa.lkml@gmail.com> wrote:

> Andrew Morton, Tue, May 06, 2008 21:22:56 +0200:
> > 
> > I've had this happen before and I don't know what to do to make it stop. 
> > Usually sufficient fiddling will prevent it from happening.
> > 
> > 
> > y:/usr/src/git26> cat .git/branches/linux-next 
> > git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git
> > 
> > y:/usr/src/git26> git-checkout master
> > Switched to branch "master"
> > y:/usr/src/git26> cat kernel/*.c|sum
> > 34439  2057
> > y:/usr/src/git26> git-checkout linux-next
> > Switched to branch "linux-next"
> > y:/usr/src/git26> cat kernel/*.c|sum     
> > 34439  2057
> 
> This is not a good indication of a failed checkout (they could point
> to the same commit, for one).

How could they?  linux-next includes a directory called ./Next and a file
in that directory called ./Next/Trees, and that is not present after the
`git-checkout linux-next'.

> Try "gitk master...linux-next" (or "git
> log master..linux-next", "git diff master linux-next")

These come up empty.  But there is a 12.4MB diff between mainline and
linux-next.

> > y:/usr/src/git26> git-checkout origin 
> > Note: moving to "origin" which isn't a local branch
> > If you want to create a new branch from this checkout, you may do so
> > (now or later) by using -b with the checkout command again. Example:
> >   git checkout -b <new_branch_name>
> > HEAD is now at 5717922... Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
> 
> This is not an error. The commit was checked out (and HEAD was
> "detached").
> 
> > y:/usr/src/git26> cat kernel/*.c|sum          
> > 34439  2057
> 
> Again, it is no indication nothing happened. "gitk HEAD...linux-next"
> 
> > y:/usr/src/git26> git --version
> > git version 1.5.5.rc1
> > 
> > help?
> 
> Look at "git branch -av" (it shows both local and remote branches and
> commits they point to).

y:/usr/src/git26> git-branch -av | grep '^\*'
* master               5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
y:/usr/src/git26> git-checkout linux-next    
Switched to branch "linux-next"
y:/usr/src/git26> git-branch -av | grep '^\*'
* linux-next           5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb

y:/usr/src/git26> ls -l Next 
ls: cannot access Next: No such file or directory

> Maybe it will give you a hint. "gitk --all" is
> interesting too, seldom though (it becomes very confusing very fast if
> you have many branches with complicated history each).

hm, lots of stuff there.


Thing is, sometimes `git-checkout linux-next' works.  Sometimes it
inexplicably doesn't work and there is no indication from git that it
didn't work.

Usually my git problems are root-caused down to my lack of a PhD in
hermeneutic metaphysiology, but not this time, methinks

```

## Junio C Hamano, 2008-05-07 00:19

Subject: Re: git-checkout sometimes silently fails
Message-ID: <7v4p9bge4q.fsf@gitster.siamese.dyndns.org>
URL: https://gitlist.dev/e/7v4p9bge4q.fsf%40gitster.siamese.dyndns.org
In-Reply-To: <20080506171052.340d643e.akpm@linux-foundation.org>

```
Andrew Morton <akpm@linux-foundation.org> writes:

> y:/usr/src/git26> git-branch -av | grep '^\*'
> * master               5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
> y:/usr/src/git26> git-checkout linux-next    
> Switched to branch "linux-next"
> y:/usr/src/git26> git-branch -av | grep '^\*'
> * linux-next           5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb

So your two local branches 'master' and 'linux-next' both point at the
same commit, 5717922.

"git checkout <branchname>" is to check out the local branch name.  You
expect "git checkout master" and then "git checkout linux-next" to check
out two different commits because linux-next _should_ have been updated to
the latest from sfr repository.  But it appears to me that that is not the
case.

Perhaps "git fetch linux-next" hasn't been run, before "git checkout" was
attempted?

```

## Jeff King, 2008-05-07 00:19

Subject: Re: git-checkout sometimes silently fails
Message-ID: <20080507001919.GA8633@sigill.intra.peff.net>
URL: https://gitlist.dev/e/20080507001919.GA8633%40sigill.intra.peff.net
In-Reply-To: <20080506171052.340d643e.akpm@linux-foundation.org>

```
On Tue, May 06, 2008 at 05:10:52PM -0700, Andrew Morton wrote:

> > > y:/usr/src/git26> git-checkout master
> > > Switched to branch "master"
> > > y:/usr/src/git26> cat kernel/*.c|sum
> > > 34439  2057
> > > y:/usr/src/git26> git-checkout linux-next
> > > Switched to branch "linux-next"
> > > y:/usr/src/git26> cat kernel/*.c|sum     
> > > 34439  2057
> > 
> > This is not a good indication of a failed checkout (they could point
> > to the same commit, for one).
> 
> How could they?  linux-next includes a directory called ./Next and a file
> in that directory called ./Next/Trees, and that is not present after the
> `git-checkout linux-next'.

But you don't show us that in your example. There is nothing in your
example to indicate that they are not simply pointing at the same
commit...

> > Try "gitk master...linux-next" (or "git
> > log master..linux-next", "git diff master linux-next")
> 
> These come up empty.  But there is a 12.4MB diff between mainline and
> linux-next.

And if these all come up empty, then they _are_ pointing to the same
commit. When you say "but there is a 12.4MB diff..." do you mean "there
_should_ be such a diff?" In that case, it seems that your linux-next
ref is pointing to an unexpected commit.

So the problem is not with git-checkout, but rather that you are not
checking out what you think you are checking out. And so we need to
figure out how you got into that state.

What command did you use to create the linux-next branch? Have you used
git-reset to move the branch tip around?

-Peff

```

## Andrew Morton, 2008-05-07 00:43

Subject: Re: git-checkout sometimes silently fails
Message-ID: <20080506174348.8d99fe4e.akpm@linux-foundation.org>
URL: https://gitlist.dev/e/20080506174348.8d99fe4e.akpm%40linux-foundation.org
In-Reply-To: <7v4p9bge4q.fsf@gitster.siamese.dyndns.org>

```
On Tue, 06 May 2008 17:19:01 -0700 Junio C Hamano <gitster@pobox.com> wrote:

> Andrew Morton <akpm@linux-foundation.org> writes:
> 
> > y:/usr/src/git26> git-branch -av | grep '^\*'
> > * master               5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
> > y:/usr/src/git26> git-checkout linux-next    
> > Switched to branch "linux-next"
> > y:/usr/src/git26> git-branch -av | grep '^\*'
> > * linux-next           5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
> 
> So your two local branches 'master' and 'linux-next' both point at the
> same commit, 5717922.
> 
> "git checkout <branchname>" is to check out the local branch name.  You
> expect "git checkout master" and then "git checkout linux-next" to check
> out two different commits because linux-next _should_ have been updated to
> the latest from sfr repository.  But it appears to me that that is not the
> case.

I did a git-fetch of linux-next yesterday.

> Perhaps "git fetch linux-next" hasn't been run, before "git checkout" was
> attempted?

I reran `git-fetch linux-next' and that downlaoded a heap of stuff (perhaps
necause linux-next rebases every time?) and after this, `git-checkout
linux-next' gives me what I expect.

But how come I couldn't check out yesterday's linux-next?

```

## Andrew Morton, 2008-05-07 00:54

Subject: Re: git-checkout sometimes silently fails
Message-ID: <20080506175442.845ca8fa.akpm@linux-foundation.org>
URL: https://gitlist.dev/e/20080506175442.845ca8fa.akpm%40linux-foundation.org
In-Reply-To: <20080507001919.GA8633@sigill.intra.peff.net>

```
On Tue, 6 May 2008 20:19:19 -0400 Jeff King <peff@peff.net> wrote:

> On Tue, May 06, 2008 at 05:10:52PM -0700, Andrew Morton wrote:
> 
> > > > y:/usr/src/git26> git-checkout master
> > > > Switched to branch "master"
> > > > y:/usr/src/git26> cat kernel/*.c|sum
> > > > 34439  2057
> > > > y:/usr/src/git26> git-checkout linux-next
> > > > Switched to branch "linux-next"
> > > > y:/usr/src/git26> cat kernel/*.c|sum     
> > > > 34439  2057
> > > 
> > > This is not a good indication of a failed checkout (they could point
> > > to the same commit, for one).
> > 
> > How could they?  linux-next includes a directory called ./Next and a file
> > in that directory called ./Next/Trees, and that is not present after the
> > `git-checkout linux-next'.
> 
> But you don't show us that in your example. There is nothing in your
> example to indicate that they are not simply pointing at the same
> commit...
> 
> > > Try "gitk master...linux-next" (or "git
> > > log master..linux-next", "git diff master linux-next")
> > 
> > These come up empty.  But there is a 12.4MB diff between mainline and
> > linux-next.
> 
> And if these all come up empty, then they _are_ pointing to the same
> commit. When you say "but there is a 12.4MB diff..." do you mean "there
> _should_ be such a diff?" In that case, it seems that your linux-next
> ref is pointing to an unexpected commit.
> 
> So the problem is not with git-checkout, but rather that you are not
> checking out what you think you are checking out.

That sounds a decent theory.

> And so we need to
> figure out how you got into that state.

Well it happens pretty regularly.  I have now lost that state but I'll save
it next time.  I'm not able to pinpoint exactly what causes it to occur.

> What command did you use to create the linux-next branch?

I edited 

y:/usr/src/git26> cat .git/branches/linux-next 
git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git

and did git-fetch once per day, approx.

> Have you used
> git-reset to move the branch tip around?

My git-fetching script does that:

doit()
{
	tree=$1
	upstream=$2

	cd $GIT_TREE
	git reset --hard "$upstream"
	git fetch "$tree" || exit 1
	git merge --no-commit 'test merge' HEAD FETCH_HEAD > /dev/null

	{
		git_header "$tree"
		git log --no-merges ORIG_HEAD..FETCH_HEAD
		git diff --patch-with-stat ORIG_HEAD
	} >$PULL/$tree.patch
	{
		echo DESC
		echo $tree.patch
		echo EDESC
		git_header "$tree"
		git log --no-merges ORIG_HEAD..FETCH_HEAD
	} >$PULL/$tree.txt
	git reset --hard "$upstream"
}

(Linus suggested an updated version of this but afaict that won't change
anything)

But, as I say, usually this script leaves the tree in a sane state.  But
sometimes it leaves it in a i-cant-check-stuff-out state.  It's not
specific to linux-next, either: I've seen this for a long time, on and off.
Prior to linux-next's existence.

```

## Björn Steinbrink, 2008-05-07 01:32

Subject: Re: git-checkout sometimes silently fails
Message-ID: <20080507013240.GA13661@atjola.homenet>
URL: https://gitlist.dev/e/20080507013240.GA13661%40atjola.homenet
In-Reply-To: <20080506175442.845ca8fa.akpm@linux-foundation.org>

```
On 2008.05.06 17:54:42 -0700, Andrew Morton wrote:
> On Tue, 6 May 2008 20:19:19 -0400 Jeff King <peff@peff.net> wrote:
> 
> > On Tue, May 06, 2008 at 05:10:52PM -0700, Andrew Morton wrote:
> > 
> > > > > y:/usr/src/git26> git-checkout master
> > > > > Switched to branch "master"
> > > > > y:/usr/src/git26> cat kernel/*.c|sum
> > > > > 34439  2057
> > > > > y:/usr/src/git26> git-checkout linux-next
> > > > > Switched to branch "linux-next"
> > > > > y:/usr/src/git26> cat kernel/*.c|sum     
> > > > > 34439  2057
> > > > 
> > > > This is not a good indication of a failed checkout (they could point
> > > > to the same commit, for one).
> > > 
> > > How could they?  linux-next includes a directory called ./Next and a file
> > > in that directory called ./Next/Trees, and that is not present after the
> > > `git-checkout linux-next'.
> > 
> > But you don't show us that in your example. There is nothing in your
> > example to indicate that they are not simply pointing at the same
> > commit...
> > 
> > > > Try "gitk master...linux-next" (or "git
> > > > log master..linux-next", "git diff master linux-next")
> > > 
> > > These come up empty.  But there is a 12.4MB diff between mainline and
> > > linux-next.
> > 
> > And if these all come up empty, then they _are_ pointing to the same
> > commit. When you say "but there is a 12.4MB diff..." do you mean "there
> > _should_ be such a diff?" In that case, it seems that your linux-next
> > ref is pointing to an unexpected commit.
> > 
> > So the problem is not with git-checkout, but rather that you are not
> > checking out what you think you are checking out.
> 
> That sounds a decent theory.
> 
> > And so we need to
> > figure out how you got into that state.
> 
> Well it happens pretty regularly.  I have now lost that state but I'll save
> it next time.  I'm not able to pinpoint exactly what causes it to occur.
> 
> > What command did you use to create the linux-next branch?
> 
> I edited 
> 
> y:/usr/src/git26> cat .git/branches/linux-next 
> git+ssh://master.kernel.org/pub/scm/linux/kernel/git/sfr/linux-next.git
> 
> and did git-fetch once per day, approx.
> 
> > Have you used
> > git-reset to move the branch tip around?
> 
> My git-fetching script does that:
> 
> doit()
> {
> 	tree=$1
> 	upstream=$2
> 
> 	cd $GIT_TREE
> 	git reset --hard "$upstream"
> 	git fetch "$tree" || exit 1
> 	git merge --no-commit 'test merge' HEAD FETCH_HEAD > /dev/null
> 
> 	{
> 		git_header "$tree"
> 		git log --no-merges ORIG_HEAD..FETCH_HEAD
> 		git diff --patch-with-stat ORIG_HEAD
> 	} >$PULL/$tree.patch
> 	{
> 		echo DESC
> 		echo $tree.patch
> 		echo EDESC
> 		git_header "$tree"
> 		git log --no-merges ORIG_HEAD..FETCH_HEAD
> 	} >$PULL/$tree.txt
> 	git reset --hard "$upstream"
> }
> 
> (Linus suggested an updated version of this but afaict that won't change
> anything)
> 
> But, as I say, usually this script leaves the tree in a sane state.  But
> sometimes it leaves it in a i-cant-check-stuff-out state.  It's not
> specific to linux-next, either: I've seen this for a long time, on and off.
> Prior to linux-next's existence.

Hm, that very much looks like it would mess things up whenever you're
not on the upstream branch already.

While this should do no harm:
git checkout master
doit linux-next master

This will make your linux-next branch point to the same commit as
master:
git checkout linux-next
doit linux-next master

Adding a '"git checkout "$upstream"' (maybe with -f?) before the first
reset --hard should avoid that then.

Björn

```

## Johannes Sixt, 2008-05-07 08:51

Subject: Re: git-checkout sometimes silently fails
Message-ID: <48216DAD.50902@viscovery.net>
URL: https://gitlist.dev/e/48216DAD.50902%40viscovery.net
In-Reply-To: <20080506171052.340d643e.akpm@linux-foundation.org>

```
Andrew Morton schrieb:
> y:/usr/src/git26> git-branch -av | grep '^\*'
> * master               5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
> y:/usr/src/git26> git-checkout linux-next    
> Switched to branch "linux-next"
> y:/usr/src/git26> git-branch -av | grep '^\*'
> * linux-next           5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb

You did not show us the output of 'git branch -av'. Do you happen to see
something like this in the output:

* master               5717922 Merge branch 'for_linus'
  linux-next           5717922 Merge branch 'for_linus'
  linux-next/HEAD      1234567 Something completely different
  linux-next/master    1234567 Something completely different

In this case, your local branch 'linux-next' is probably a left-over from
earlier experiments. The last two branches are actually what you want to
refer to. Normally, the 'linux-next/HEAD' part allows you to refer to
'linux-next/master' by saying simply 'linux-next'. But unfortunately, your
local branch name 'linux-next' takes precedence.

'git fetch' never updates your local branch, but only 'linux-next/master'
(and its alias 'linux-next/HEAD' aka 'linux-next').

To return to a sane state, do 'git branch -D linux-next'.

-- Hannes

```

## J. Bruce Fields, 2008-05-07 15:09

Subject: Re: git-checkout sometimes silently fails
Message-ID: <20080507150927.GA11447@fieldses.org>
URL: https://gitlist.dev/e/20080507150927.GA11447%40fieldses.org
In-Reply-To: <7v4p9bge4q.fsf@gitster.siamese.dyndns.org>

```
On Tue, May 06, 2008 at 05:19:01PM -0700, Junio C Hamano wrote:
> Andrew Morton <akpm@linux-foundation.org> writes:
> 
> > y:/usr/src/git26> git-branch -av | grep '^\*'
> > * master               5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
> > y:/usr/src/git26> git-checkout linux-next    
> > Switched to branch "linux-next"
> > y:/usr/src/git26> git-branch -av | grep '^\*'
> > * linux-next           5717922 Merge branch 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jwessel/linux-2.6-kgdb
> 
> So your two local branches 'master' and 'linux-next' both point at the
> same commit, 5717922.
> 
> "git checkout <branchname>" is to check out the local branch name.  You
> expect "git checkout master" and then "git checkout linux-next" to check
> out two different commits because linux-next _should_ have been updated to
> the latest from sfr repository.  But it appears to me that that is not the
> case.
> 
> Perhaps "git fetch linux-next" hasn't been run, before "git checkout" was
> attempted?

Might also be worth checking whether there happens to be a tag (or
something else?) named the same as one of the branches?  I remember the
public -mm git repo, for example, having a tag named "master".  Yuch.

Grepping through git-for-each-ref output might shed some light.

--b.

```
