This is an old question, but judging by dates of answers and comments it's still relevant, so I figured I'd add my few cents.
If the commit you want to clone is a tip of the branch or a tag, you can - as mentioned in other answers - do:
git clone --depth 1 --branch <branch/tag name> <repository URL>
If, however, you want to clone the commit by its SHA (as indicated in the question), you need to run several commands:
mkdir -p <local repository directory>
cd <local repository directory>
git init
git remote add origin <repository URL>
git fetch --depth 1 origin <commit SHA>
git checkout FETCH_HEAD
If you have to do it often, you could make it into a function/cmdlet.
For example in Bash:
git_clone_commit() {
mkdir -p "$1"
pushd "$1"
git init
git remote add origin "$3"
git fetch --depth 1 origin "$2"
git checkout FETCH_HEAD
git submodule update --init --recursive
popd
}
and then
git_clone_commit <local repository directory> <commit SHA> <repository URL>
--depth
? – Dagger