Git contains a multitude of commands and day-to-day workflows that you use to manage or maintain source control of a Git repository. With such a command you will be able to perform basic tasks of tracking and compromising files.
In addition to all this, Git contains tools for selecting review , 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 that you may need at some point. And one of them is Short SHA-1 .
Refresh the question: Could not collisions of different hashs start with the same characters?
Git is smart enough to figure out what you intend to type if you provide the first few hash , as long as your SHA-1 has at least four characters and is not ambiguous , that is, only one hash in the current repository that starts with partial SHA-1 .
Git can find a short, single abbreviation for its SHA-1 values using the --abbrev-commit
command for the git log
command. The output will be shorter, but unique hash . The Git pattern uses seven characters , but may be longer or shorter if needed, as long as the unambiguous SHA-1 is maintained, and usually 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 --abbrev-commit
command causes, instead of displaying the 40-byte hexadecimal acknowledgment hash , only show 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
to the information output if it becomes much more readable to people using 80-column terminals.
But how do I easily get SHA short or complete for any commit in the history of your current branch, useful for reverting and sharing specific code states with others.
You can use the command: git rev-list --max-count=1 --abbrev-commit --skip=#
and gain cramp in your fingers, OR install Githash
Explanation of the command
-
rev-list
: get SHA for any commit in the history of your current branch
-
--max-count=n
: Limits the number of commits
in the output.
-
--skip=n
: The failure number confirms before starting to show the confirmation output.