how to clone an old git-commit (and some more questions about git)

I have a git-repository of my project with about 20 commits. I know how to clone the actual commit with git clone,

  • but how can I "clone" an old commit?
  • is there a really good git-GUI (imho qgit is not a good GUI)?
  • what exactly are "branches"?
  • when I want to release 0.1, 0.2 and so on, what is the best way to mark these commits in git?
  • what are the big differences to svn?

Solution 1:

A git repository contains the all history at all time.
So when you are cloning a repository, you are cloning it with its full history, and then, you can make a branch from whatever commit you want:

 $ git checkout -b aNewBranch SHA1

with SHA1 representing the commit id from which you want to proceed.


Branches in Git are just a way to keep track of one path of a DAG (Directed Acyclic Graph) which is the set of commits representing the history of a Git repository.
It is a mere pointer you assign to one of those commits, and it will keep moving along with each new commits.

branches

See Pro Git book for more.


You can mark a specific commit with a tag, which, like a branch, is a mere pointer, but an immutable one (it wont move when you make new commit).
You will use preferably annotated tags, which are stored as full objects in the Git database. They’re checksummed; contain the tagger name, e-mail, and date; have a tagging message; and can be signed and verified with GNU Privacy Guard (GPG).


The "Graphical Interfaces" section of InterfacesFrontendsAndTools page on Git Wiki lists the various GUI for Git at the moment.


You will see many questions about the difference between Git and SVN: see my answer (or this one) for example.
My most complete answer about the fundamental differences between Git and SVN is here:
"which of the two is better:git or SVN".

Solution 2:

There are a few questions in this post, here is my take on some answers:

First, to "clone" a previous commit, you can do something like this:

git clone REPO_URL
git checkout HEAD~1 // checks out the last commit's first parent

Use ~1 to access the last commit's first parent, and increment the number to get the parent's parent and so on. More on tilde and caret notation.

The two commands above will put you in a detached HEAD state, which may or may not be important based on context. For example, it isn't important if you are cloning as part of your deployment scripts and all you care about is accessing a previous commit (say, as part of a rollback strategy).

If you need to begin work from this point in history, you can run

git checkout -b NEW_BRANCH_NAME

A good git GUI? For me SourceTree is the best.

What are branches? In my own words, a branch is just a very easy way to pivot. Say you are working on one branch, master and you want to try an experiment. Easy, just git checkout -b experiment and you are quickly in a safe place to break stuff.

What's different between git and svn?

git is a distribute version control system. svn is not. Also, branching (mentioned above) is easier in git.

For tagging, I don't know if there's "One True Way" (is there ever?) but just explore the git tag command. One great thing about git is how easy it is to clone a duplicate of your repo on your local computer (or wherever) and do whatever you want to it and see what happens. If you mess something up, just delete the directory. So, you can experiment with git tag in some testing directory and see what you like.