threads / discuss / 20855

.git and retrieving full source tree for own project(s)

Subject: .git and retrieving full source tree for own project(s)

## tl;dr

3 messages between Sep 4, 2009 and Sep 4, 2009.

replies: 2people: 2as markdown or json

armencho@gmail.com· Sep 4, 2009, 19:52 UTC · lore
Hi all,

I just started with git and suprisingly or unsurprisingly everything works, and I love it. I had been working on a software project, and i ran "git init" in its source tree, which created the ".git". I added all files with "git add ." and first-time committed them all using "git commit -a -m "Imported project files". I also did couple three commits after that and well, everything works.

What I am wondering about is, what is gits identity for a repository? I don't share or publish the source directory anywhere, and just for testing I removed everything but the ".git" directory and tried "git checkout" and "git checkout master". To my surprise, the files in repository did NOT reappear, contrary to what I thought. Doesn't checkout update/recreate the project file tree according to the "trunk" snapshot?

Now, I did all this just out of curiosity, but to my understanding everything that is needed for working with the project is stored in ".git", right? Even if all project files mysteriously disappear, "git checkout" should bring the copy of master branch back, no? If not, what is the way to tell git I want full copy of a snapshot?

Junio C Hamano· Sep 4, 2009, 20:04 UTC · re: armencho@gmail.com · lore

Re: .git and retrieving full source tree for own project(s)

"armencho@gmail.com" <armencho@gmail.com> writes:
> What I am wondering about is, what is gits identity for a repository?
> I don't share or publish the source directory anywhere, and just for
> testing I removed everything but the ".git" directory and tried "git
> checkout" and "git checkout master".

"git checkout" is a short-hand for "git checkout HEAD" which is to request "switch to the branch denoted by HEAD, i.e. the current branch, while keeping my local changes to the work tree and the index".

"git checkout master" is a request to "switch to the master branch, while keeping my local changes to the work tree and the index".

In this case, your "delete everything" is your local change, and git did its best to preserve it while switching branches.

If you want to "copy this and that files and directories out of the commit at the tip of the current branch and deposit them in my work tree and index", you would say

    $ git checkout HEAD this that

so a request for checking everything out would be a natural extension of the above that would be:

    $ git checkout HEAD .

If you want to "copy this and that files and directories out of the index and deposit them in my work tree", you would say

    $ git checkout this that
armencho@gmail.com· Sep 4, 2009, 20:18 UTC · re: Junio C Hamano · lore

Re: .git and retrieving full source tree for own project(s)

On Fri, Sep 4, 2009 at 22:04, Junio C Hamano<gitster@pobox.com> wrote:
Show 20 quoted lines
> In this case, your "delete everything" is your local change, and git did
> its best to preserve it while switching branches.
>
> If you want to "copy this and that files and directories out of the
> commit at the tip of the current branch and deposit them in my work tree
> and index", you would say
>
>    $ git checkout HEAD this that
>
> so a request for checking everything out would be a natural extension of
> the above that would be:
>
>    $ git checkout HEAD .
>
> If you want to "copy this and that files and directories out of the index
> and deposit them in my work tree", you would say
>
>    $ git checkout this that
>
>

This makes sense now. I have tested this and it all functions as you said. Thanks for your help!

← back to recent threads