[英]Getting git commit id on Qt qmake project at make time
On Windows 10 Qt 5.15, I'm getting git commit id on Qt qmake project at qmake time with在 Windows 10 Qt 5.15,我在 qmake 时间在 Qt qmake 项目上获得 git commit id
COMMIT = '\\"$$system(git rev-parse --verify master)\\"'
DEFINES += COMMIT_VERSION=\"$${COMMIT}\"
And on main.cpp
I can print that with qDebug() << COMMIT_VERSION;
在
main.cpp
上,我可以使用qDebug() << COMMIT_VERSION;
打印它
Since some commits do not require a full project rebuild I'm getting old (not the latest) commit ids.由于某些提交不需要完整的项目重建,因此我变老了(不是最新的)提交 ID。
How can I get that updated on every build?我怎样才能在每次构建时更新它?
I use Ubuntu but for doing what you want I try this:我使用 Ubuntu 但是为了做你想做的事我试试这个:
what you do is like in cmd or terminal always type this command :你所做的就像在 cmd 中一样,或者终端总是输入这个命令:
git rev-parse --verify master
so for doing this I use QProcess
like this:所以为了做到这一点,我使用
QProcess
是这样的:
first of all, I create one bash file and put that command there.首先,我创建一个 bash 文件并将该命令放在那里。 I always put commands in one shell script file because it's easy and just put
.sh
file in the start process.我总是将命令放在一个 shell 脚本文件中,因为它很简单,只需将
.sh
文件放在启动过程中即可。
test.sh测试.sh
#!/bin/sh
cd /home/parisa/projectFolderName;git rev-parse --verify master
and this is code:这是代码:
QProcess *myProcess = new QProcess();
myProcess->start("/home/parisa/untitled1/test.sh");
myProcess->waitForFinished(3);
QString str = myProcess->readAll();
qDebug() << "git id : " << str;
delete myProcess;
and this is the output:这是 output:
In QTCreator short cut Alt + K or Alt + G will show you the git log.在QTCreator 中,快捷键 Alt + K或Alt + G将显示 git 日志。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.