17

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.

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
Habba
  • 395
  • 2
  • 3
  • 14

2 Answers2

22

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).

VonC
  • 1,042,979
  • 435
  • 3,649
  • 4,283
1

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.

Malatesh Patil
  • 3,683
  • 1
  • 12
  • 14