Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pulling a specific version with git

Tags:

I need the source code from a specific version of a project (The SonarQube project), but I can't figure out how to pull it from git.

I've added the repo as a remote (git add remote origin) and pulled the latest version from the master branch, but that is not the version I need.

I know the commit I need is d25bc0e, but when I try "git fetch origin master d25bc0e" I get the error "fatal: couldn't find remote ref d25bc0e".

It could be I'm doing something very wrong, I am not very experienced with Git.

like image 208
Habba Avatar asked Oct 15 '14 15:10

Habba


People also ask

How do I download a specific version of Github?

For those wanting to download a specific Commit, steps are below: Go to "Commits" Click the "<>" icon to the right of the desired commit. Select Clone or Download.

Can I pull specific file from git?

While you're working on a repository in Git, you might need to checkout a specific file from another branch. Luckily, Git offers many possible ways to do this task quickly. One of the easiest solutions is to use the git checkout command with the specified file as an argument.


2 Answers

You cannot pull a specific commit.

See more at "Pull a specific commit from a remote git repository"

Once cloned, you can checkout a specific commit (but you would be in a detached branch mode, which is ok if all you need to do is read, and not commit)

git checkout d25bc0e

If you had to do some modification, starting from that commit, you would create a new branch:

git checkout -b newBranch d25bc0e

Note: since Oct. 2014, you might be able to fetch only one commit (Git 2.5, June 2015), only if the remote server allows it.
But here, I would still recommend the classic workflow (clone+checkout).

like image 82
VonC Avatar answered Sep 20 '22 22:09

VonC


If you want to get the specific version. You can get it via commit id.

You can get the commit id in logs.

So first try git log to get specific commit id

Then try

git reset --hard commit_id

But this will not allow you to commit the version. This is read only of a specific version.

like image 21
Malatesh Patil Avatar answered Sep 20 '22 22:09

Malatesh Patil