Subdirectories in extracted directory of previous version do not disappear in Git?

I am trying to use git checkout <hash> <directory>to verify a previous revision of a directory in my repo. This works to restore files in a directory to their previous state, the only problem is that the subdirectories that were added after the check that I checked do not disappear.

For example, if my directory structure was as follows:

HEAD:
thing/dir1/
thing/dir2/

HEAD^:
thing/dir1/

If I do git checkout <hash>, then I go into separate HEAD mode and everything is fine. If I do instead git checkout <hash> thing/, the contents thing/dir1/will return, but thing/dir2/remain in place.

The launch git statusshows the file changes from thing/dir1/, but does not mention thing/dir2/. This is strange because, in the context of HEAD ^, thing/dir2/it should not exist and therefore must disappear. git cleandoesn't help because it doesn't even appear as unplayed.

Is there a way to check a previous revision of a directory that is perfect without having to check the entire working tree?

UPDATE:

This seems to work:

git reset <hash> thing/
git checkout <hash> thing/
git clean -fd thing/

This leaves my working tree and index in a strange state, but has the desired effect.

+3
source share
2 answers

From http://git-scm.com/docs/git-checkout :

. , git checkout HEAD .

:

<paths> --patch, gitcheckout . ( ). -b -track . (.. , ) .

, , HEAD, , , HEAD ^

, /dir 2 , , - HEAD (, HEAD ), tree-ish, -ish ( /dir 2). , /dir 1, HEAD ^ , /dir 2 , HEAD.

+1

, git checkout <hash> git . , .

, thing/dir2/ git status, HEAD, thing/dir1 .

thing/, , ?

rm thing/
git checkout <hash> thing/

, . ! ( .)

+1

All Articles