如何获取Git中当前提交的哈希?
当前回答
我知道的最简洁的方式是:
git show --pretty=%h
如果您需要哈希的特定位数,可以添加:
--abbrev=n
其他回答
在gitbash上,只需运行$git日志-1
您将看到,这些行遵循您的命令。
commit d25c95d88a5e8b7e15ba6c925a1631a5357095db .. (info about your head)
d25c95d88a5e8b7e15ba6c925a1631a5357095db, is your SHA for last commit.
git show-ref --head --hash head
如果你追求速度,Deestan提到的方法
cat .git/refs/heads/<branch-name>
比这里列出的任何其他方法都快得多。
我知道的最简洁的方式是:
git show --pretty=%h
如果您需要哈希的特定位数,可以添加:
--abbrev=n
使用git rev list--max count=1 HEAD
主要git repo和子模块的漂亮打印:
echo "Main GIT repo:"
echo $(git show -s --format=%H) '(main)'
echo "Sub-modules:"
git submodule status | awk '{print $1,$2}'
示例输出:
3a032b0992d7786b00a8822bbcbf192326160cf9 (main)
7de695d58f427c0887b094271ba1ae77a439084f sub-module-1
58f427c0887b01ba1ae77a439084947de695d27f sub-module-2
d58f427c0887de6957b09439084f4271ba1ae77a sub-module-3
推荐文章
- 为什么我需要显式地推一个新分支?
- 如何撤消最后的git添加?
- Rubymine:如何让Git忽略Rubymine创建的.idea文件
- Gitignore二进制文件,没有扩展名
- Git隐藏错误:Git隐藏弹出并最终与合并冲突
- 了解Git和GitHub的基础知识
- 没有。Git目录的Git克隆
- Git与Mercurial仓库的互操作性
- 忽略git中修改(但未提交)的文件?
- “git restore”命令是什么?“git restore”和“git reset”之间有什么区别?
- Git合并与强制覆盖
- Git拉另一个分支
- 在Bash命令提示符上添加git分支
- 如何更改Git日志日期格式
- git pull -rebase和git pull -ff-only之间的区别