On Mon, 22 Oct 2012 02:39:29 -0700 (PDT) Thirukumaran Kubendran <[email protected]> wrote:
> If there are 1,2,3..8 versions of a project and 8 being the latest. I > would like to clone version 5. Also is there a way to list all the > versions available. Depends on how do you define "versions". The first fact to understand and keep in mind is about history. The history maintained in a Git repository is a set of DAGs [1] formed by commits plus a set of the so-called "references" (or just "refs" for short). Both branches and tags in Git are references. The second fact is that a repository is usually cloned as a whole (that's why the operation is named "clone") -- you do have certain level of control about what will be fetched during cloning (the so called "shallow cloning" [2]) and which branch will be checked out after cloning into a non-bare repository, but these options are really limited in their scope as what you want to achieved is to be done *after* cloning, not *when* cloning. The third fact is that after you cloned a repository, you have all the possibilities to inspect any "version" of the code contained in the history of that repository. This means you can check out (using `git checkout`) anything which ultimately resolves to the name of a commit, that is, you can pass the `git checkout` command the SHA-1 name of any commit or any reference (and that means any branch name or tag name). Now let's get back to your "versions". Since any commit is just a snapshot of the whole repository, each commit represents a version of the file set tracked by that repository. Git has no direct support for somehow representing versions in the manager's sense (as in "a version of a product") but Git tags are routinely used exactly for this -- usually when a state of the repository is used to prepare a release of some product, the commit referring to that state is tagged using certain descriptive name, like "v1.0.0" or so. Since virtually any project which uses Git adopts tags to track "managerial versions", the probable answers to your questions are as follows. To list all available "versions", run `git tag` in a cloned repository. To "get" the state of the project for a given "version", just check out the necessary tag. Note that checking out is not necessary for certain tasks -- for instance, you can do `git archive ... <that_tag>` to get a tarball with all the files as they were recorded by the commit pointed to by <that_tag>. Finally, a note of caution about checking out tags: since tags, contrary to branches, are immovable, checking out a tag puts your work tree in the so called "detached HEAD" state -- you can freely modify the files and record any number of commits, but they won't be on any branch, and the only thing which will refer to the tip commit in this series is the special ref "HEAD" (that's why this state is called as it's called). This state is nothing really scary -- if you think your commits are worth keeping around, just create a branch out of the HEAD by doing `git checkout -b <newbranch>`. But if you know up front you will be changing the code after checking it out, you're probably better off creating a branch at the commit pointed to by the tag of interest, and then working on that branch: git checkout -b <newbranch> <that_tag> 1. Directed Acyclic Graph 2. Read the git-clone manual page for more info. -- You received this message because you are subscribed to the Google Groups "Git for human beings" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/git-users?hl=en.
