git tag 常用操作-創建、查看、推送、刪除等


創建tag

1.創建tag:
git tag -a v0.0.1

或者 對某一提交的信息打tag標簽,末尾是一個commit id
git tag -a v0.0.1 cc16905

2.創建tag帶有說明信息:
git tag -a v0.0.1 -m "version 0.0.1, tag info"

3.創建輕量的標簽tag(快速創建tag):
git tag v0.0.1
沒有使用 -a, -s, -m 選項

4.對某一個提交信息打tag
比如說給提交的信息打tag,commit id為 be7a3e4
git tag v0.0.2 be7a3e4

5.對以前提交的信息打tag
git log --pretty=oneline

$ git log --pretty=oneline
cc16905383a5924c64912699460fbda0091b704d (HEAD -> master, tag: v0.0.1, origin/master, origin/HEAD) demo
be7a3e40a31de7f992262a10175e8846b861dc1b  router
a1f20fe1edfcf393bb6f4a3db1e0fb52477a6bf6  code
a42f81b86dbbffb07547b83415c628e3733dbdfc  lint
6d4d71917f533c1582c4ab0cc1bb080c753f6baf readme

上面這條命令顯示了全部的commit id信息,有沒有簡短點的commit 信息,看下面的命令。

git log --pretty=oneline --abbrev-commit
上面這條命令可以顯示你以前提交的日志信息。

$ git log --pretty=oneline --abbrev-commit
cc16905 (HEAD -> master, tag: v0.0.1, origin/master, origin/HEAD) demo
be7a3e4  router
a1f20fe  code
a42f81b  lint
6d4d719 readme
6d7e181 struct code
be072d3 go.mod

然后在用上面提到的命令: git tag tag-name commit-id
比如給:be072d3 go.mod,它的commit id為 be072d3,打tag-name為: mod,命令:
git tag mod be072d3

查看tag信息

1.查看某個tag信息
git show v0.0.1

2.查看所有tag信息
git tag

把標簽推送到遠程

1.推送某一tag到遠程倉庫:
git push origin v0.0.1

2.一次推送多個標簽
git push origin --tags

git push --tags

刪除標簽

1.刪除標簽
git tag -d v0.0.1

根據標簽檢出

1.檢出標簽
git checkout v0.0.1

根據標簽回退

1.首先查看要回退的標簽信息
git show v0.0.1

$ git show v0.0.1
tag v0.0.1
Tagger: jiujuan <jixxxxx@163.com>
Date:   Fri May 12 16:46:27 2019 +0800

version 0.0.1

commit cc16905383a5924c64912699460fbda0091b704d (HEAD -> master, tag: v0.0.1, origin/master, origin/HEAD)
Author: jiujuan <jixxxxx@163.com>
Date:   Fri May 12 16:41:50 2020 +0800

    demo

上面的commit id很長,我們只取前面7位就好了,git會自動識別

2.第二步:版本回退,將主干分支回退到某個版本
git reset --hard cc16905

回退完畢,其實就是把head指針指向了指定版本位置.

其他常用的回退命名,回退到上一個版本命令:
git reset --hard HEAD

參考

git-標簽


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM