Bananach Bananach - 3 years ago 134
Git Question

Git: Checkout old version of directory under new name

How do I check out a previous version of a directory under a new name?

(I have and always had a directory

foo
in my repo. I want to create a directory
foo_old
in my current working tree whose contents are those of
HEAD~2:foo
. I need both versions at the same time, to make sure they give the same results, testing this requires quite a bit of code and requires having both results available at the same time (the results are not simply integers, say), so I cannot simply checkout
HEAD~2
temporarily to do what I want)

This question asks how to check out a previous version of a file under a new name, but the accepted answer cannot be generalized to directories.

Answer Source

You could do very simple:

git co -b new-branch-name    # create and go to new branch, just to be sure
git slg                      # get the commit hash you need for next step
git co [commit-hash]         # now you get the old folder by the state you need it

then copy the directory you need to your desktop. ( You are now in HEAD detached)

git co new-branch-name       # cause you are in detached head go back to new-branch

On desktop rename the directory to foo_old and copy paste it to where you need it in project.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download