[英]Git: How to include working tree status in git log --pretty=format…?
I'm using the following command in an Eclipse CDT pre-build step, to generate a header file containing my current short Git hash as a string macro: 我在Eclipse CDT的预构建步骤中使用以下命令,生成一个头文件,其中包含我当前的短Git哈希作为字符串宏:
git log --pretty=format:'#define GIT_HASH_STRING "%h"' -n 1 > ../Inc/gitcommit.h
Works great, but it doesn't indicate the status of the working tree. 效果很好,但是它并不指示工作树的状态。 Like when running git submodule status
, if there are working tree changes, I'd like it to spit out something like 就像在运行git submodule status
,如果有工作树更改,我希望它吐出类似
a289542-dirty
Is this possible? 这可能吗? I checked the man page for git-log formats, but didn't see anything that looked pertinent. 我检查了手册页中的git-log格式,但没有看到任何相关的内容。
Context: The GIT_HASH_STRING
macro is displayed when issuing a version
command via the CLI of an embedded device. 上下文:通过嵌入式设备的CLI发出version
命令时,将显示GIT_HASH_STRING
宏。 If I can include a -dirty
flag in the string, it can serve as a warning that the device is running an unreleased version of firmware that doesn't align with a specific commit. 如果我可以在字符串中包含-dirty
标志,则可以作为警告,说明该设备正在运行未发行版本的固件,该版本与特定提交不符。
The git log
command does not inspect the work-tree, so it cannot do this. git log
命令不检查工作树,因此它不能这样做。
There are many commands that do inspect the work-tree. 有许多命令可以检查工作树。 One simple one is git describe
: 一个简单的就是git describe
:
git describe --always --dirty
will print out a string that will end with -dirty
if the work-tree or the index is modified with respect to the current commit (ie, in the same situations where git status
would say something is staged for commit or not staged for commit). 如果相对于当前提交修改了工作树或索引,则将打印出一个以-dirty
结尾的字符串(即,在git status
表示某些内容已暂存为提交或未暂存为提交的相同情况下) 。
If you want to check submodules as well, you will need more. 如果还要检查子模块,则将需要更多。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.