In my repo, how long must the longest hash prefix be to prevent any overlap?

后端 未结 2 561
不思量自难忘°
不思量自难忘° 2020-12-16 18:43

The --abbrev-commit flag can be used in conjunction with git log and git rev-list in order to show partial prefixes instead of the ful

2条回答
  •  悲&欢浪女
    2020-12-16 19:17

    The following shell script, when run in a local repo, prints the length of the longest prefix required to prevent any overlap among all prefix hashes of commit objects of that repository.

    MAX_LENGTH=4;
    
    git rev-list --abbrev=4 --abbrev-commit --all | \
      ( while read -r line; do
          if [ ${#line} -gt $MAX_LENGTH ]; then
            MAX_LENGTH=${#line};
          fi
        done && printf %s\\n "$MAX_LENGTH"
      )
    

    The last time I edited this answer, the script printed

    • "9" when run in a clone of the Git-project repo,
    • "9" when run in a clone of the OpenStack repo,
    • "11" when run in a clone of the Linux-kernel repo.

提交回复
热议问题