7 1 建立標籤

2021-09-14 06:42:26 字數 2380 閱讀 7861

在git中打標籤非常簡單,首先,切換到需要打標籤的分支上:

$ git branch

* dev

master

$ git checkout master

switched to branch 'master'

然後,敲命令git tag就可以打乙個新標籤:

$ git tag v1.0
可以用命令git tag檢視所有標籤:

$ git tag

v1.0

預設標籤是打在最新提交的commit上的。有時候,如果忘了打標籤,比如,現在已經是周五了,但應該在周一打的標籤沒有打,怎麼辦?

方法是找到歷史提交的commit id,然後打上就可以了:

$ git log --pretty=oneline --abbrev-commit

12a631b (head -> master, tag: v1.0, origin/master) merged bug fix 101

4c805e2 fix bug 101

e1e9c68 merge with no-ff

f52c633 add merge

cf810e4 conflict fixed

5dc6824 & ******

14096d0 and ******

b17d20e branch test

d46f35e remove test.txt

b84166e add test.txt

519219b git tracks changes

e43a48b understand how stage works

e475afc add distributed

eaadf4e wrote a readme file

比方說要對add merge這次提交打標籤,它對應的commit idf52c633,敲入命令:

$ git tag v0.9 f52c633
再用命令git tag檢視標籤:

$ git tag

v0.9

v1.0

注意,標籤不是按時間順序列出,而是按字母排序的。可以用git show檢視標籤資訊:

$ git show v0.9

commit f52c63349bc3c1593499807e5c8e972b82c8f286 (tag: v0.9)

author: michael liao date: fri may 18 21:56:54 2018 +0800

add merge

diff --git a/readme.txt b/readme.txt

...

可以看到,v0.9確實打在add merge這次提交上。

還可以建立帶有說明的標籤,用-a指定標籤名,-m指定說明文字:

$ git tag -a v0.1 -m "version 0.1 released" 1094adb
用命令git show可以看到說明文字:

$ git show v0.1

tag v0.1

tagger: michael liao date: fri may 18 22:48:43 2018 +0800

version 0.1 released

commit 1094adb7b9b3807259d8cb349e7df1d4d6477073 (tag: v0.1)

author: michael liao date: fri may 18 21:06:15 2018 +0800

diff --git a/readme.txt b/readme.txt

...

注意:標籤總是和某個commit掛鉤。如果這個commit既出現在master分支,又出現在dev分支,那麼在這兩個分支上都可以看到這個標籤。
小結

命令git tag用於新建乙個標籤,預設為head,也可以指定乙個commit id

命令git tag -a -m "blablabla..."可以指定標籤資訊;

命令git tag可以檢視所有標籤。

動態建立標籤

動態的建立div並在div中包含乙個的標籤並為他們新增屬性 for var i 0 i var odiv document.createelement div 建立div odiv.classname jizhan 設定div的classname odiv.div hehe 建立div的id odi...

動態建立標籤頁

一 首先新增標籤頁 員工資訊 add tab style width 100 href class easyui linkbutton 新標籤頁 width 100 title adduser.html href class easyui linkbutton 新增員工 width 100 titl...

建立與合併分支 解決衝突 建立標籤 操作標籤

建立與合併分支小結 git鼓勵大量使用分支 檢視分支 git branch 建立分支 git branch 切換分支 git checkout 或者git switch 建立 切換分支 git checkout b 或者git switch c 合併某分支到當前分支 git merge 刪除分支 g...