首頁·終端機命令

git describe

git

用法

git describe [--tags] [--dirty]

以最近的標籤為基準,把目前的提交命名成 v1.2.0-5-gabc1234 這樣;預設只看附註標籤,輕量標籤要加 --tags,一個標籤都沒有時要加 --always。

常用選項

選項含義
--tagsuse lightweight tags too, not just annotated ones
--dirtyappend -dirty when the working tree has changes
--alwaysfall back to a bare hash when no tag is found
--longalways the full tag-count-hash form
--abbrev=<n>how many hash digits to print
--match <pattern>only consider matching tags

範例

git describe --tags --dirty

prints something like v1.2.0-5-gabc1234-dirty

git describe --always

never fails, even in a repository with no tags

git describe --match "v*" --long

ignores tags that are not versions

難的地方在於復原有好幾種:把分支的指向挪走,和補一個反向提交,不是一回事。

怎麼看

  • 方括號 [ ] 表示這部分可以不寫。
  • 省略號 … 表示可以寫多個。
  • 選項區分大小寫——有些命令裡 -r 和 -R 不是一回事。

常見問題

Q. git describe 是做什麼的?

以最近的標籤為基準,把目前的提交命名成 v1.2.0-5-gabc1234 這樣;預設只看附註標籤,輕量標籤要加 --tags,一個標籤都沒有時要加 --always。

Q. 怎麼寫?

git describe [--tags] [--dirty] —— 方括號表示可以省略的部分。

Q. 值得記的選項有幾個?

這裡列了 6 個,完整列表在 man git。這條命令屬於git。

相關命令

man 手冊: man git-describe