獲取簡短的 Git 版本雜湊 - Get the short Git version hash

語言: CN / TW / HK

問題:

Is there a cleaner way to get the short version hash of HEAD from Git?有沒有更簡潔的方法可以從 Git 獲取HEAD的短版本雜湊?

I want to see the same output as I get from:我想看到與我得到的輸出相同的輸出:

 git log -n 1 | head -n 1 | sed -e 's/^commit //' | head -c 8

I originally used the above command to generate a version string, but this is even better:我最初使用上面的命令來生成版本字串,但這更好:

git describe --tags

It will output strings like 0.1.12 (tagged commit) or 0.1.11-5-g0c85fbc (five commits after the tag).它將輸出像0.1.12 (標記提交)或0.1.11-5-g0c85fbc (標記後五次提交)這樣的字串。


解決方案:

參考一: https://stackoom.com/question/NtMz
參考二: Get the short Git version hash
「其他文章」