K
K
Kirill Olenev2015-04-22 15:43:35
git
Kirill Olenev, 2015-04-22 15:43:35

Is it possible to clone a git repository by sha1 (commit hash)?

In the project, we build builds through Hudson.
To get the code, we do git clone
I want to build builds for a specific branch and commit.
The problem is that everything works fine for the branch name, i.e.:
git clone our_repo/repo_name.git -b master_Branch_Name
But if we put a hash instead of the branch name, say:
git clone our_repo/repo_name.git -b c0ff7a5663a73790746a084b023c3f75ec6b0465
We get fatal: Remote branch c0ff7a5663a73790746a084b023c3f75ec6b0465 not found in upstream origin
Yes, you can first
git clone our_repo/repo_name.git
...
git checkout
c0ff7a5663a73790746a084b023c3f75ec6b0465
Or why doesn't git clone -b work?

Answer the question

In order to leave comments, you need to log in

3 answer(s)
K
Kirill Olenev, 2015-04-22
@agent10

Looks like I found something. You can't do this for security reasons.
Read more here:
git.661346.n2.nabble.com/Fetch-by-SHA-missing-td56...
and here:
thread.gmane.org/gmane.comp.version-control.git/73...

Y
Yuri Puzynya, 2015-04-22
@3y3

I would advise using tags in this case, it will make life easier for everyone:

git tag -a v0.0.7 -m "Tagged version 0.0.7"
git push --follow-tags

The documentation does not say that this flag can accept sha1

A
Alexey Yakhnenko, 2015-04-22
@ayahnenko

because
-b
Instead of pointing the newly created HEAD to the branch pointed to by the cloned repository's HEAD, point to branch instead. In a non-bare repository, this is the branch that will be checked out. --branch can also take tags and detaches the HEAD at that commit in the resulting repository.
Use tags, and in general, what's wrong with 2 lines?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question