# checkout on an empty directory fails

7 messages from 2012-01-05 to 2012-01-05. Participants: René Doß, Nguyen Thai Ngoc Duy, Ramkumar Ramachandra, Thomas Rast, Holger Hellmuth, Dirk Süsserott.
Thread: https://gitlist.dev/t/29296

## René Doß, 2012-01-05 10:09

Subject: checkout on an empty directory fails
Message-ID: <4F0576D9.4030207@gmx.de>
URL: https://gitlist.dev/e/4F0576D9.4030207%40gmx.de

```
I have a clean derectory ang the git database. Now I want check out the 
master.
The master is the last commit. The files name  are displayed but not 
stored out in directory.

Why can not I  check out?

René Doß



red@linux-nrd1:~/iso/a> ls -a
.  ..  .git
red@linux-nrd1:~/iso/a> git checkout master
D       SP601_RevC_annotated_master_ucf_8-28-09.ucf
D       rtl/ether_speed.vhd
D       rtl/ether_top.vhd
D       rtl/ether_tx.vhd
D       rtl/takt.vhd
D       sim/makefile
D       sim/tb_ether_top.vhd
Already on 'master'
red@linux-nrd1:~/iso/a> ls
red@linux-nrd1:~/iso/a>

```

## Nguyen Thai Ngoc Duy, 2012-01-05 11:06

Subject: Re: checkout on an empty directory fails
Message-ID: <CACsJy8A42n4t+WqGaTx7vDQ3jP_YkD1bB0WL9amrrg1B4eOx7w@mail.gmail.com>
URL: https://gitlist.dev/e/CACsJy8A42n4t%2BWqGaTx7vDQ3jP_YkD1bB0WL9amrrg1B4eOx7w%40mail.gmail.com
In-Reply-To: <4F0576D9.4030207@gmx.de>

```
On Thu, Jan 5, 2012 at 5:09 PM, René Doß <doss@gmx.de> wrote:
> I have a clean derectory ang the git database. Now I want check out the
> master.
> The master is the last commit. The files name  are displayed but not stored
> out in directory.
>
> Why can not I  check out?

try "git checkout ." but be careful because this command overwrites
any changes you have in the directory.

>
> red@linux-nrd1:~/iso/a> ls -a
> .  ..  .git
> red@linux-nrd1:~/iso/a> git checkout master
> D       SP601_RevC_annotated_master_ucf_8-28-09.ucf
> D       rtl/ether_speed.vhd
> D       rtl/ether_top.vhd
> D       rtl/ether_tx.vhd
> D       rtl/takt.vhd
> D       sim/makefile
> D       sim/tb_ether_top.vhd
> Already on 'master'
> red@linux-nrd1:~/iso/a> ls
> red@linux-nrd1:~/iso/a>
-- 
Duy

```

## Ramkumar Ramachandra, 2012-01-05 11:07

Subject: Re: checkout on an empty directory fails
Message-ID: <CALkWK0knVa3V9mX86WhmXmC3_SBPitgAzh_9RAXmWeQcgf=hRw@mail.gmail.com>
URL: https://gitlist.dev/e/CALkWK0knVa3V9mX86WhmXmC3_SBPitgAzh_9RAXmWeQcgf%3DhRw%40mail.gmail.com
In-Reply-To: <4F0576D9.4030207@gmx.de>

```
Hi René,

René Doß wrote:
> I have a clean derectory ang the git database. Now I want check out the
> master.
> [...]
>
> red@linux-nrd1:~/iso/a> ls -a
> .  ..  .git
> red@linux-nrd1:~/iso/a> git checkout master
> D       SP601_RevC_annotated_master_ucf_8-28-09.ucf
> [...]

In such situations, "git status" usually has something helpful to say.
 You're already on the "master" branch, and you can reset your
worktree with `git reset --hard` (caution: please read the manpage).

-- Ram

```

## Thomas Rast, 2012-01-05 11:13

Subject: Re: checkout on an empty directory fails
Message-ID: <87d3ayz9k3.fsf@thomas.inf.ethz.ch>
URL: https://gitlist.dev/e/87d3ayz9k3.fsf%40thomas.inf.ethz.ch
In-Reply-To: <4F0576D9.4030207@gmx.de>

```
René Doß <doss@gmx.de> writes:

> I have a clean derectory ang the git database. Now I want check out
> the master.

Ok, but why?  What problem were you really trying to solve?

> red@linux-nrd1:~/iso/a> git checkout master
> D       SP601_RevC_annotated_master_ucf_8-28-09.ucf
> D       rtl/ether_speed.vhd
> D       rtl/ether_top.vhd
> D       rtl/ether_tx.vhd
> D       rtl/takt.vhd
> D       sim/makefile
> D       sim/tb_ether_top.vhd
> Already on 'master'

git-checkout considers this an uncommitted change compared to the
current branch (HEAD).  It actually ensures that you do not lose such
changes.

To get your files back, you can use the file-argument form of checkout

  git checkout -- .

or the "really give me back the HEAD state, period" form of git-reset

  git reset --hard

Both of those *will* destroy uncommitted changes with no recourse or
backup, so be careful.

-- 
Thomas Rast
trast@{inf,student}.ethz.ch

```

## René Doß, 2012-01-05 12:38

Subject: RE: Re: checkout on an empty directory fails
Message-ID: <4F0599E0.7090902@gmx.de>
URL: https://gitlist.dev/e/4F0599E0.7090902%40gmx.de
In-Reply-To: <CACsJy8A42n4t+WqGaTx7vDQ3jP_YkD1bB0WL9amrrg1B4eOx7w@mail.gmail.com>

```
  Thank you for your help. I can not understand what is the mistake?  
qgit displays me the tree correct.
git status says not special informations.
Only git  checkout .    works.

What means the point in checkout?



René


red@linux-nrd1:~/iso/a> git status
# On branch master
# Changed but not updated:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working 
directory)
#
#       deleted:    SP601_RevC_annotated_master_ucf_8-28-09.ucf
#       deleted:    rtl/ether_speed.vhd
#       deleted:    rtl/ether_top.vhd
#       deleted:    rtl/ether_tx.vhd
#       deleted:    rtl/takt.vhd
#       deleted:    sim/makefile
#       deleted:    sim/tb_ether_top.vhd
#
no changes added to commit (use "git add" and/or "git commit -a")

ed@linux-nrd1:~/iso/a> ls
red@linux-nrd1:~/iso/a> git reset --hard
HEAD is now at efb7b86 Simulation ergaenzt
red@linux-nrd1:~/iso/a> git checkout master
Already on 'master'
red@linux-nrd1:~/iso/a> git checkout .
red@linux-nrd1:~/iso/a> ls
rtl  sim  SP601_RevC_annotated_master_ucf_8-28-09.ucf <--here are the 
files back!!!!
red@linux-nrd1:~/iso/a>

```

## Holger Hellmuth, 2012-01-05 13:59

Subject: Re: checkout on an empty directory fails
Message-ID: <4F05ACD6.6040603@ira.uka.de>
URL: https://gitlist.dev/e/4F05ACD6.6040603%40ira.uka.de
In-Reply-To: <4F0599E0.7090902@gmx.de>

```
On 05.01.2012 13:38, René Doß wrote:
> git status says not special informations.

  versus

> red@linux-nrd1:~/iso/a> git status
> # On branch master
> # Changed but not updated:
> # (use "git add/rm <file>..." to update what will be committed)
> # (use "git checkout -- <file>..." to discard changes in working directory)
> #
> # deleted: SP601_RevC_annotated_master_ucf_8-28-09.ucf
> # deleted: rtl/ether_speed.vhd
> # deleted: rtl/ether_top.vhd
> # deleted: rtl/ether_tx.vhd
> # deleted: rtl/takt.vhd
> # deleted: sim/makefile
> # deleted: sim/tb_ether_top.vhd
> #

This *is* special information: It tells you that master has those 7 
files but your working directory has none of them (i.e. it is as if you 
had deleted them from your working directory).

"git checkout <branch>" switches between branches, *but* leaves changes 
you made (files you edited, added or deleted) intact! This is so you can 
switch branches before commiting if you suddenly realize you are in the 
wrong branch.

"git checkout -- <paths...>" or in your case "git checkout -- ." is 
different, it really overwrites the files in your working dir with the 
versions stored somewhere else, by default from the index.

 > What means the point in checkout?

"." is simply your current directory

```

## Dirk Süsserott, 2012-01-05 19:33

Subject: Re: checkout on an empty directory fails
Message-ID: <4F05FB05.3090706@dirk.my1.cc>
URL: https://gitlist.dev/e/4F05FB05.3090706%40dirk.my1.cc
In-Reply-To: <4F05ACD6.6040603@ira.uka.de>

```
Am 05.01.2012 14:59 schrieb Holger Hellmuth:
> On 05.01.2012 13:38, René Doß wrote:
>> git status says not special informations.
> 
>  versus
> 
>> red@linux-nrd1:~/iso/a> git status
>> # On branch master
>> # Changed but not updated:
>> # (use "git add/rm <file>..." to update what will be committed)
>> # (use "git checkout -- <file>..." to discard changes in working
>> directory)
>> #
>> # deleted: SP601_RevC_annotated_master_ucf_8-28-09.ucf
>> # deleted: rtl/ether_speed.vhd
>> # deleted: rtl/ether_top.vhd
>> # deleted: rtl/ether_tx.vhd
>> # deleted: rtl/takt.vhd
>> # deleted: sim/makefile
>> # deleted: sim/tb_ether_top.vhd
>> #
> 
> This *is* special information: It tells you that master has those 7
> files but your working directory has none of them (i.e. it is as if you
> had deleted them from your working directory).
> 
> "git checkout <branch>" switches between branches, *but* leaves changes
> you made (files you edited, added or deleted) intact! This is so you can
> switch branches before commiting if you suddenly realize you are in the
> wrong branch.
> 
> "git checkout -- <paths...>" or in your case "git checkout -- ." is
> different, it really overwrites the files in your working dir with the
> versions stored somewhere else, by default from the index.
> 
>> What means the point in checkout?
> 
> "." is simply your current directory

Another way of reviving the deleted files and restore the master branch is

$ git checkout -f master # or git checkout --force master

This will unconditionally checkout master and overwrite the local
changes, including the deletions Holger mentioned.

For me, "checkout --force" is more intuitive than "reset --hard" or
"checkout .".

    Dirk

```
