Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find long SHA from short SHA for git diff

I was generating difference / changes done in the commit so that I can upload it in ReviewBoard.

I used "git show d9f7121e8ebd4d1f789dab9f8214ada2h480b9cf". It gave me diff something like...

diff --git a/src/index.php b/src/index.php
index 3cfa8e8..7f8440d 100644
--- a/src/index.php
+++ b/src/index.php
@@ -12,10 +12,13 @@
 .test {
     .input;
     width: auto;
+    border-width: 5px;
+    border-radius: 50%;
 }

When I create .patch file of this diff. Reviewboard rejects it saying "'3cfa8e8' revision is not valid format. SHA1 is too short".

So I wanted to get long SHA1 from short SHA1 '3cfa8e8'.

I did 'git show 3cfa8e8'. It just shows me some content of file. Doesn't show me anything else.

Any help how can I get long SHA?

(Note:- All the sha and file diff are example to demonstrate the problem)

like image 555
Umakant Patil Avatar asked Sep 26 '13 07:09

Umakant Patil


People also ask

How long is a git commit SHA?

A commit in git always has a hash that contains 40 characters.

How do I see git diff?

You can run the git diff HEAD command to compare the both staged and unstaged changes with your last commit. You can also run the git diff <branch_name1> <branch_name2> command to compare the changes from the first branch with changes from the second branch. Order does matter when you're comparing branches.

What is git diff command?

Comparing changes with git diff Diffing is a function that takes two input data sets and outputs the changes between them. git diff is a multi-use Git command that when executed runs a diff function on Git data sources. These data sources can be commits, branches, files and more.

How many characters is a short git hash?

Generally, eight to ten characters are more than enough to be unique within a project. One of the largest Git projects, the Linux kernel, is beginning to need 12 characters out of the possible 40 to stay unique. 7 digits are the Git default for a short SHA, so that's fine for most projects.


1 Answers

git rev-parse <short sha> should do the trick.

See also the git rev-parse manpage.

like image 51
Nevik Rehnel Avatar answered Sep 27 '22 21:09

Nevik Rehnel