39

I have a short git commit hash of length 8 characters. I want to get a complete hash from remote server. I tried getting the branch name from the commit hash and then getting the full commit hash from branch name but it only works for the latest commit. What could be the best possible way to achieve what I want?

Usman
  • 601
  • 1
  • 6
  • 10
  • What do you mean by "from remote server"? Do you have a local clone of the repository? – Philipp Wendler Jan 18 '17 at 10:27
  • I do have a local clone of the repository but i need to do it before i fetch. (I am actually working on a python script that automatically does everything that's why i don't want to fetch everytime) – Usman Jan 18 '17 at 10:33

2 Answers2

75

git rev-parse will give you what you want.

$ git rev-parse 3cdd5d
3cdd5d19178a54d2e51b5098d43b57571241d0ab
Joe
  • 26,561
  • 11
  • 64
  • 84
6

You can use the --pretty option of the show command:

$ git show --pretty=%H 62a0505
62a0505e8204115b8b9c8a95bfa264a8c0896a93

(assuming you have a local clone of the repo)

mamapitufo
  • 4,400
  • 2
  • 23
  • 19