Git contains a plethora of day-to-day commands and workflows that you use to manage or maintain source control of a Git repository. With such command you will be able to perform basic tasks of tracking and compromising files.
Beyond all this Git contains tools for review selection, where you will be able to explore a number of very powerful things that Git can do. They are not tools that you will necessarily use on a day-to-day basis, but you may need at some point. And one of them is Short SHA-1.
Rephrase the question: There could be different hash collisions that start with the same characters?
Git is smart enough to figure out what you want to type if you provide the first characters of hash, since his SHA-1 partial has at least four characters and is not ambiguous, that is, only one hash in the current repository starting with the SHA-1 partial.
Git can find a short and unique abbreviation for its values SHA-1 through the command --abbrev-commit
for the command git log
. The exit will be hash shorter but unique. Git’s default uses seven characters, but may be longer or shorter if necessary, provided that the SHA-1 unequivocal and generally eight to ten characters are more than enough to be unique within a project. For example:
$ git log --abbrev-commit --pretty=oneline
ca82a6d changed the version number
085bb3b removed unnecessary test code
a11bef0 first commit
Note: The command --abbrev-commit
makes it, instead of showing the hash complete 40 byte hexadecimal confirmation, show only a partial prefix. The default number of digits can be specified with --abbrev = <n>
(which also modifies the output of diff
, if displayed). Add --pretty = oneline
for the output of information to become much more readable for people using terminals of 80 columns.
But how do I easily get the short or full SHA for any commit in your current branch history, useful for reversing and sharing specific code states with others.
You can use the command: git rev-list --max-count=1 --abbrev-commit --skip=#
and cramp your fingers, or install the Githash
Explanation of command
rev-list
: get SHA for any commit in the history of its current branch
--max-count=n
: Limits the number of commits
on the way out.
--skip=n
: Failure number confirms before starting to show confirmation output.