iOS - Git 打標籤(分布式版本控制系統)

來源:互聯網
上載者:User

標籤:很多   ann   推送   using   aaa   ota   等等   出現   push   

前言
  • 像其他版本控制系統(VCS)一樣,Git 可以給曆史中的某一個提交打上標籤,以示重要。比較有代表性的是人們會使用這個功能來標記發布結點(v1.0 等等)。
1、列出標籤
  • 在 Git 中列出已有的標籤是非常簡單直觀的。只需要輸入 git tag,這個命令以字母順序列出標籤,但是它們出現的順序並不重要。

    $ git tag
    v0.1v1.3
  • 你也可以使用特定的模式尋找標籤。

    • 例如,Git 自身的原始碼倉庫包含標籤的數量超過 500 個。如果只對 1.8.5 系列感興趣,可以運行。

      # git tag -l [特定的模式]$ git tag -l 'v1.8.5*'
      v1.8.5v1.8.5-rc0v1.8.5-rc1v1.8.5-rc2v1.8.5-rc3v1.8.5.1v1.8.5.2v1.8.5.3v1.8.5.4v1.8.5.5
2、建立附註標籤
  • Git 使用兩種主要類型的標籤:輕量標籤(lightweight)與附註標籤(annotated)。

  • 附註標籤是儲存在 Git 資料庫中的一個完整對象。它們是可以被校正的;其中包含打標籤者的名字、電子郵件地址、日期時間;還有一個標籤資訊;並且可以使用 GNU Privacy Guard(GPG)簽名與驗證。

  • 通常建議建立附註標籤,這樣你可以擁有以上所有資訊;但是如果你只是想用一個臨時的標籤,或者因為某些原因不想要儲存那些資訊,輕量標籤也是可用的。

  • 在 Git 中建立一個附註標籤是很簡單的。最簡單的方式是當你在運行 tag 命令時指定 -a 選項。

    # git tag -a [標籤名] -m [標籤說明]$ git tag -a v1.4 -m 'my version 1.4'
    $ git tagv0.1v1.3v1.4
    • -m 選項指定了一條將會儲存在標籤中的資訊。如果沒有為附註標籤指定一條資訊,Git 會運行編輯器要求你輸入資訊。
  • 這時,如果在標籤上運行 git show,你會看到顯示了打標籤者的資訊、打標籤的日期時間、附註資訊,然後顯示具體的提交資訊。

3、建立輕量標籤
  • 輕量標籤很像一個不會改變的分支,它只是一個特定提交的引用。

  • 輕量標籤本質上是將提交校正和儲存到一個檔案中,沒有儲存任何其他資訊。建立輕量標籤,不需要使用 -a-s-m 選項,只需要提供標籤名字。

    # git tag [標籤名]-lw$ git tag v1.4-lw
    $ git tagv0.1v1.3v1.4v1.4-lwv1.5
  • 這時,如果在標籤上運行 git show,你不會看到額外的標籤資訊,命令只會顯示出具體的提交資訊。

4、顯示標籤資訊
  • 通過使用 git show 命令可以看到標籤資訊與對應的提交資訊,

    • 附註標籤會顯示打標籤者的資訊、打標籤的日期時間、附註資訊,然後顯示具體的提交資訊
    • 輕量標籤會只會顯示出具體的提交資訊。

      # git show [標籤名]$ git show v1.4
    • 附註標籤

      tag v1.4Tagger: Ben Straub <[email protected]>Date:   Sat May 3 20:19:12 2014 -0700my version 1.4commit ca82a6dff817ec66f44342007202690a93763949    Author: Scott Chacon <[email protected]>Date:   Mon Mar 17 21:52:11 2008 -0700    changed the version number
    • 輕量標籤

      $ git show v1.4-lwcommit ca82a6dff817ec66f44342007202690a93763949Author: Scott Chacon <[email protected]>Date:   Mon Mar 17 21:52:11 2008 -0700    changed the version number
5、後期打標籤
  • 你也可以對過去的提交打標籤。假設提交曆史是這樣的。

    $ git log --pretty=oneline15027957951b64cf874c3557a0f3547bd83b3ff6 Merge branch 'experiment'a6b4c97498bd301d84096da251c98a07c7723e65 beginning write support0d52aaab4479697da7686c15f77a3d64d9165190 one more thing6d52a271eda8725415634dd79daabbc4d9b6008e Merge branch 'experiment'0b7434d86859cc7b8c3d5e1dddfed66ff742fcbc added a commit function4682c3261057305bdd616e23b64b0857d832627b added a todo file166ae0c4d3f420721acbb115cc33848dfcc2121a started write support9fceb02d0ae598e95dc970b74767f19372d61af8 updated rakefile964f16d36dfccde844893cac5b347e7b3d44abbc commit the todo8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme
  • 現在,假設在 v1.2 時你忘記給項目打標籤,也就是在 “updated rakefile” 提交。你可以在之後補上標籤。要在那個提交上打標籤,你需要在命令的末尾指定提交的校正和(或部分校正和)。

    # git tag -a [標籤名] [校正和] -m [標籤說明]$ git tag -a v1.2 9fceb02 -m "version 1.2"
    • 可以看到你已經在那次提交上打上標籤了。

      $ git tagv0.1v1.2v1.3v1.4v1.4-lwv1.5$ git show v1.2tag v1.2Tagger: Scott Chacon <[email protected]>Date:   Mon Feb 9 15:32:16 2009 -0800version 1.2commit 9fceb02d0ae598e95dc970b74767f19372d61af8Author: Magnus Chacon <[email protected]>Date:   Sun Apr 27 20:43:35 2008 -0700    updated rakefile...
6、共用標籤
  • 預設情況下,git push 命令並不會傳送標籤到遠程倉程式庫伺服器上。在建立完標籤後你必須顯式地推送標籤到共用伺服器上。這個過程就像共用遠程分支一樣,你可以運行 git push origin [tagname]

    # git push [branch-name] [tagname]$ git push origin v1.5
    Counting objects: 14, done.Delta compression using up to 8 threads.Compressing objects: 100% (12/12), done.Writing objects: 100% (14/14), 2.05 KiB | 0 bytes/s, done.Total 14 (delta 3), reused 0 (delta 0)To [email protected]:schacon/simplegit.git * [new tag]         v1.5 -> v1.5
  • 如果想要一次性推送很多標籤,也可以使用帶有 --tags 選項的 git push 命令。這將會把所有不在遠程倉程式庫伺服器上的標籤全部傳送到那裡。

    # git push [branch-name] --tags$ git push origin --tags  
    Counting objects: 1, done.Writing objects: 100% (1/1), 160 bytes | 0 bytes/s, done.Total 1 (delta 0), reused 0 (delta 0)To [email protected]:schacon/simplegit.git * [new tag]         v1.4 -> v1.4 * [new tag]         v1.4-lw -> v1.4-lw
    • 現在,當其他人從倉庫中複製或拉取,他們也能得到你的那些標籤。
7、檢出標籤
  • 在 Git 中你並不能真的檢出一個標籤,因為它們並不能像分支一樣來回移動。如果你想要工作目錄與倉庫中特定的標籤版本完全一樣,可以使用 git checkout -b [branch-name] [tagname] 在特定的標籤上建立一個新分支。

    # git checkout -b [branch-name] [tagname]$ git checkout -b version2 v2.0.0
    Switched to a new branch 'version2'
    • 當然,如果在這之後又進行了一次提交,version2 分支會因為改動向前移動了,那麼 version2 分支就會和 v2.0.0 標籤稍微有些不同,這時就應該當心了。

iOS - Git 打標籤(分布式版本控制系統)

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.