I tried --abbrev=7, but it seems to have no effect.
so it is not possible to get a fixed abbrev length?
It is, but only with With Git 2.29 (Q4 2020): Before, the output from the "diff" family of the commands had abbreviated object names of blobs involved in the patch, but its length was not affected by the --abbrev option.
Now it is.
See commit 3046c7f (21 Aug 2020) by Đoàn Trần Công Danh (sgn).
See commit fc7e73d (21 Aug 2020) by brian m. carlson (bk2204).
(Merged by Junio C Hamano -- gitster -- in commit 096c948, 31 Aug 2020)
diff: index-line: respect --abbrev in object's name
Signed-off-by: Đoàn Trần Công Danh
A handful of Git's commands respect --abbrev for customizing length of abbreviation of object names.
For diff-family, Git supports 2 different options for 2 different purposes:
--full-index for showing diff-patch object's name in full, and
--abbrev to customize the length of object names in diff-raw and diff-tree header lines, without any options to customise the length of object names in diff-patch format.
When working with diff-patch format, we only have two options, either full index, or default abbrev length.
Although, that behaviour is documented, it doesn't stop users from trying to use --abbrev with the hope of customising diff-patch's objects' name's abbreviation.
Let's allow the blob object names shown on the "index" line to be abbreviated to arbitrary length given via the "--abbrev" option.
To preserve backward compatibility with old script that specify both --full-index and --abbrev, always show full object id if --full-index is specified.
diff-options now includes in its man page:
In diff-patch output format, --full-index takes higher precedence, i.e. if --full-index is specified, full blob names will be shown regardless of --abbrev.
Non default number of digits can be specified with --abbrev=<n>.
The documentation on the "--abbrev=<n>" option did not say the output may be longer than "<n>" hexdigits, which has been clarified with Git 2.30 (Q1 2021).
See commit cda34e0 (04 Nov 2020) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit ee13beb, 11 Nov 2020)
doc: clarify that --abbrev=<n> is about the minimum length
Helped-by: Derrick Stolee
Early text written in 2006 explains the "--abbrev=<n>" option to "show only a partial prefix", without saying that the length of the partial prefix is not necessarily the number given to the option to ensure that the output names the object uniquely.
Update documentation for the diff family of commands, "blame", "branch --verbose", "ls-files" and "ls-tree" to stress that the short prefix must uniquely refer to an object, and is merely the mininum number of hexdigits used in the prefix.
diff-options now includes in its man page:
lines, show the shortest prefix that is at least '<n>'
hexdigits long that uniquely refers the object.
git blame now includes in its man page:
abbreviated object name, use <m>+1 digits, where <m> is at least <n> but ensures the commit object names are unique.
git branch now includes in its man page:
--abbrev=<n>
In the verbose listing that show the commit object name,
show the shortest prefix that is at least '<n>' hexdigits
long that uniquely refers the object.