問題描述
如何檢索顯示上游狀態的 git 版本信息 (How do I retrieve git version info showing upstream state)
我想將版本信息添加到編譯到我的可執行文件中的文件中。基於這裡和這裡,我已經使用git describe
更新構建過程添加版本號,我可以檢測是否有未提交的源。
我想要什麼add 指示當前分支是否與上游存儲庫不同步。也就是說,開發人員已經承諾到他們的本地 repo 很好,但是來自尚未推送的源的構建應該被標記為這樣。
基本上,我想要與遙控器等效的‑‑dirty
。
參考解法
方法 1:
Add a git fetch
and test whether git rev‑parse HEAD HEAD@{upstream}
spits the same word twice:
git fetch
read mine theirs <<<`git rev‑parse HEAD HEAD@{upstream}`
test $mine = $theirs || echo 'not synced'