threads / discuss / 29296

checkout on an empty directory fails

Subject: checkout on an empty directory fails

## tl;dr

7 messages between Jan 5, 2012 and Jan 5, 2012.

replies: 6people: 6as markdown or json

René Doß· Jan 5, 2012, 10:09 UTC · lore

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· Jan 5, 2012, 11:06 UTC · re: René Doß · lore

Re: checkout on an empty directory fails

On Thu, Jan 5, 2012 at 5:09 PM, René Doß <doss@gmx.de> wrote:
Show 6 quoted lines
> 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.

Show 14 quoted lines
>
> 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
René Doß· Jan 5, 2012, 12:38 UTC · re: Nguyen Thai Ngoc Duy · lore

RE: Re: checkout on an empty directory fails

  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· Jan 5, 2012, 13:59 UTC · re: René Doß · lore

Re: checkout on an empty directory fails

On 05.01.2012 13:38, René Doß wrote:
> git status says not special informations.
  versus
Show 14 quoted lines
> 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· Jan 5, 2012, 19:33 UTC · re: Holger Hellmuth · lore

Re: checkout on an empty directory fails

Am 05.01.2012 14:59 schrieb Holger Hellmuth:
Show 37 quoted lines
> 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
Ramkumar Ramachandra· Jan 5, 2012, 11:07 UTC · re: René Doß · lore

Re: checkout on an empty directory fails

Hi René,
René Doß wrote:
Show 9 quoted lines
> 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· Jan 5, 2012, 11:13 UTC · re: René Doß · lore

Re: checkout on an empty directory fails

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?
Show 9 quoted lines
> 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

← back to recent threads