Reputation: 7815
If U is a git URL (e.g., an ssh URL), how can I find the SHA1 hash of a branch or tag of U without a local clone of U?
Upvotes: 6
Views: 4005
Reputation: 1323025
Make sure to use Git 2.28 (Q3 2020) if you are using git ls-remote
, since the SHA-256 migration work continues.
Since Git 2.19 (Q2 2018), Git prepares a transition from SH1 hashes to SHA2, as detailed in "Why doesn't Git use more modern SHA?"
See commit 3716d50, commit 6161ce7, commit 371c407, commit 4ddd3f5, commit f7c6a3b, commit 8fc7003, commit 54cbbe4, commit 97997e6, commit 793731f, commit 586740a, commit ac093d0 (19 Jun 2020), commit d96dab8, commit f0af95f, commit 9de0dd3, commit ab67235, commit 67e9a70, commit 7f46e7e, commit 059d806, commit 88a09a5, commit 1610dda, commit 629dffc, commit 49c9a2f, commit d553ace, commit 4b83120, commit 9dc78c2, commit b65dc2c, commit 7f60501, commit 8b85ee4, commit 452e356, commit bb095d0, commit 7c601dc, commit 48bf141, commit 84eca27, commit 82db03a, commit 122037c, commit 7c97af4, commit 9a9f0d3, commit 1349ffe, commit 2c6a403, commit bf30dbf, commit 14570dc, commit 92315e5 (25 May 2020), and commit b8615c3, commit a114296 (13 May 2020) by brian m. carlson (bk2204
).
(Merged by Junio C Hamano -- gitster
-- in commit 1221085, 06 Jul 2020)
remote-curl
: avoid truncating refs with ls-remoteSigned-off-by: brian m. carlson
Normally, the
remote-curl
transport helper is aware of the hash algorithm we're using because we're in a repo with the appropriate hash algorithm set.However, when using
git ls-remote
outside of a repository, we won't have initialized the hash algorithm properly, so usehash_to_hex_algop
to print the ref corresponding to the algorithm we've detected.
That is important since, in your case, you would use git ls-remote U
outside of any local Git repository:
git ls-remote
outside of a repository, older Git versions might be unaware of the hash algorithm used (SHA-1 vs. SHA-256).For instance:
HASH=$(git ls-remote "${REMOTE_URL}" "refs/heads/${BRANCH_NAME}" | cut -f1)
Upvotes: 0
Reputation: 606
You can use this:
git ls-remote U branch | cut -c1-7
where, 'branch' specifies the commit hash from that particular branch
Upvotes: 1