Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting the last commit hash from a remote repo without cloning

Tags:

git

github

I want to get the hash of last commit that has happened in a remote repo without cloning it. Is there a way to do this ? I found several methods but for all of them to work, I need to clone the repo first and then issue the commands to get the last commit hash.

Is there a way I can get the last commit hash from a remote git without cloning it ?

Note:

like image 313
user3678812 Avatar asked Jul 15 '14 05:07

user3678812


People also ask

How do you pull from a commit hash?

To pull up a list of your commits and their associated hashes, you can run the git log command. To checkout a previous commit, you will use the Git checkout command followed by the commit hash you retrieved from your Git log.

How can I get previous commit ID?

To find a git commit id (or hash), you can simply use the git log command. This would show you the commit history, listing the commits in chronological order, with the latest commit first.

What does git LS Remote do?

git ls-remote is one unique command allowing you to query a remote repo without having to clone/fetch it first. It will list refs/heads and refs/tags of said remote repo. It can also help resolve the actual url used by a remote repo when you have " url.


1 Answers

$ git ls-remote https://github.com/gturri/dokuJClient.git 
2fb540fc8c7e9116791638393370a2fa0f079737    HEAD
2fb540fc8c7e9116791638393370a2fa0f079737    refs/heads/master

This command can be run from any directory.

If you only want the last sha1, eg to use it in a script, you could then do:

git ls-remote https://github.com/gturri/dokuJClient.git HEAD | awk '{ print $1}'
like image 192
gturri Avatar answered Oct 05 '22 10:10

gturri