iT邦幫忙

2

Git 學習筆記_06(Git tag 標籤)

  • 分享至 

  • twitterImage
  •  

簡介

在進行專案的開發時,往往都會記錄專案的版本以防想要觀看前一個版本的程式碼。

git tag 標籤名稱 -> 新增指定名稱的tag

在簡介中有介紹了版本在大型專案開發中所佔有的重要度,而git tag能夠幫我們實現這個功能。

Step 1 : 新增一個index.html並且更改其內容並將它commit

在index.html中新增一行程式碼<h1>Hello Word in V1</h1>並且將它commit。
https://ithelp.ithome.com.tw/upload/images/20200420/201247675Pyxsq5LzD.png
https://ithelp.ithome.com.tw/upload/images/20200420/20124767ijGV3fVbTj.png

Step 2 : git tag 標籤名稱 -> 新增指定名稱的tag

利用git tag V1將此commit設定為一個名為V1的tage。
https://ithelp.ithome.com.tw/upload/images/20200420/201247672Tb6Clg1Ju.png

可以使用git tag來查看全部的tag
https://ithelp.ithome.com.tw/upload/images/20200420/20124767i7jp5VGLYg.png

Step 3 : 再次新增程式在index.html中將它Commit並新增V2 tag

https://ithelp.ithome.com.tw/upload/images/20200420/20124767TWelkY7W1n.png
https://ithelp.ithome.com.tw/upload/images/20200420/201247671trFgJTVnf.png
https://ithelp.ithome.com.tw/upload/images/20200420/20124767aOg7CX115U.png

一樣使用git tag來查看全部的tag
https://ithelp.ithome.com.tw/upload/images/20200420/20124767Na8X9rIEGE.png

git Checkout tag名稱 -> 移動HEAD到指定的tag

若我們要將專案移動到V1的版本,可以使用git checkout V1來將HEAD移動到V1 tag上。
https://ithelp.ithome.com.tw/upload/images/20200420/20124767hGipJbdZ4M.png
https://ithelp.ithome.com.tw/upload/images/20200420/201247671mKh9UOJRB.png

而返回master一樣是使用git checkout master

git tag -am "備註內容" 標籤名稱 -> 新增指定名稱的tag並備註其內容

在index.html中新增<h1>Hello Word in V3</h1>並且使用git tag -am "New code Hellio Word in V3" V3來建立新的tag,將它命名為"V3"並且給它備註說明 "新增了Hellio Word in V3這行程式碼"。
https://ithelp.ithome.com.tw/upload/images/20200420/20124767amFDDKt38q.png
https://ithelp.ithome.com.tw/upload/images/20200420/20124767XhefZkIDD0.png

要看到詳細的tag標籤與備註內容可以使用git tag -n便可以檢視到tag的備註
https://ithelp.ithome.com.tw/upload/images/20200420/20124767UCWYkeEBMc.png

git tag -d 標籤名稱-> 刪除指定標籤

可以利用git tag -d V1來刪除掉V1這個tag,刪除完後使用git tag來確認是否刪除。
https://ithelp.ithome.com.tw/upload/images/20200420/20124767bcWE2POPUz.png

參考資料 :
掌握 Git 與 Github 程式時光機


圖片
  直播研討會
圖片
{{ item.channelVendor }} {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言