Skip to contentSkip to conversation

checkout on an empty directory fails

DISCUSSION René Doß 6 participants 7 messages Jun 15, 2016

lore
Share & tools
lore

René Doß

author
#0 lore raw

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>

#1 lore raw
Quoted 2 lines · René Doß

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?

Quoted 9 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.

Signature · 2 lines
Thomas Rast
trast@{inf,student}.ethz.ch
#2 lore raw
In reply to René Doß
Quoted 6 lines · René Doß

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.

Quoted 14 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>

Signature · 1 line
Duy
author
#3 lore raw

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>

#4 lore raw
Quoted 1 line · René Doß

git status says not special informations.

versus

Quoted 6 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) #

Quoted 8 lines

# 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.

Quoted 1 line

What means the point in checkout?

"." is simply your current directory

#5 lore raw

Am 05.01.2012 14:59 schrieb Holger Hellmuth:

Quoted 30 lines · René Doß
Quoted 1 line

git status says not special informations.

versus

Quoted 7 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)
#

Quoted 8 lines

# 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.

Quoted 7 lines

"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.

Quoted 1 line

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

#6 lore raw
In reply to René Doß

Hi René,

Quoted 9 lines · René Doß

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