Home > Mobile >  How can I find who made a commit with a specific SHA, who doesn't have 7 digits?
How can I find who made a commit with a specific SHA, who doesn't have 7 digits?

Time:11-03

I have this part of this SHA : f9720a. So I want to find who made this commit, using the function git log. How am I able to do that?

CodePudding user response:

format, allows you to specify your own log output format.This is especially useful when you’re generating output for machine parsing — because you specify the format explicitly, you know it won’t change with updates to Git:

git log --pretty=format:"%H - %an
f9720a- steve mohammmad

%h--Abbreviated commit hash or %H--commit hash

%an--Author name

CodePudding user response:

If:

  • f9720a is a prefix of the full commit hash ID, and
  • f9720a is unique as a such a prefix—that is, no other commit hash ID starts with f9720a

then:

git show f9720a^{commit}

suffices.1

If this is a non-unique prefix, or not a prefix at all, you'll have to find all commits whose hash ID contains f9720a and inspect each one, as each one could be the commit in question.

In all cases you must have this commit in your Git repository. If you never have had this commit, you cannot inspect it: you must first get the commit from some Git repository that does have it.

The probability that some partial hash ID matches multiple commits depends on the number of commits. While each full commit hash ID occurs 1 out of 2160 times, each six-character prefix occurs 1 out of 224 times. Those might seem like good odds, but the birthday paradox means that 24 bits is not enough in a lot of medium-to-large repositories. Even seven characters (28 bits) is still not enough. That's why Git uses 40 characters (160 bits).


1In Windows CMD, be sure to double the ^ character. In some shells (e.g., tcsh) you may need other quoting methods.

  •  Tags:  
  • git
  • Related