git學習三——打發布標籤(tag)

NO IMAGE

比如今天要釋出一個版本了,我們要打標籤:release-0.1;


[email protected] MINGW64 /g/Git_learn/tt (master)
$ git log --pretty=oneline
6c694be844bb4af6a8b936babb957e15cd3335d0 Merge branch 'issue2'
92c7a61ebbb5cab38284f40c28ae3646fa1654d3 Merge branch 'issue1' er
3ab754e3225039cfddd8cc648b29eb9fb18e64ec issue1_file
44d307ee2687c5202d23e17563092c0b5f929da4 issue2_fiel
dee33c6d9c31c2bfe23d0539b6e1d5d3a3795bc9 Merge branch 'issue1'
45ae8155e967f12a17c6b53dd2de887992309ff0 issue1_file2
520167b60acc0c3b26147b4c46887124f78ae0a5 t
a12883e29c8ac8fd4a5b9d7d5a706b381e40965d issue1_file'
53487b9ae5a81e953ea430d670f0aa0d111db06d 01
0d7b47e5ca2df2484cda6a209b12402710e61a7f conflict fixed
391ab5fc87c91c298811033402e1142143979173 tt merge *0953
52321632a4b88aca7b540a715830e285def3e77c tt commit first
1960953e07c9fe7c15efd9a2a40baec96befd1da tt_third second commit
4aa3b67bd87e227f9fa96b1a86790f97f7d8bfeb tt_third commit
40d4754a6f1b9898b751ae513ec88d47bbc2b2a6 test

我們決定使用520167b60acc0c3b26147b4c46887124f78ae0a5 t
作為今天的釋出版本

[email protected] MINGW64 /g/Git_learn/tt (master)
$ git tag -a release-0.1 520167b6 -m "release version"
[email protected] MINGW64 /g/Git_learn/tt (master)
$ git tag -l
release
#或者這樣檢視 --decorate
[email protected] MINGW64 /g/Git_learn/tt (master)
$ git log --pretty=oneline --decorate
6c694be844bb4af6a8b936babb957e15cd3335d0 (HEAD -> master Merge branch 'issue2'
92c7a61ebbb5cab38284f40c28ae3646fa1654d3 Merge branch 'issue1' er
3ab754e3225039cfddd8cc648b29eb9fb18e64ec (issue1) issue1_file
44d307ee2687c5202d23e17563092c0b5f929da4 (issue2) issue2_fiel
dee33c6d9c31c2bfe23d0539b6e1d5d3a3795bc9 (tag: release) Merge branch 'issue1'
45ae8155e967f12a17c6b53dd2de887992309ff0 issue1_file2
520167b60acc0c3b26147b4c46887124f78ae0a5 t
a12883e29c8ac8fd4a5b9d7d5a706b381e40965d issue1_file'
53487b9ae5a81e953ea430d670f0aa0d111db06d 01
0d7b47e5ca2df2484cda6a209b12402710e61a7f conflict fixed
391ab5fc87c91c298811033402e1142143979173 tt merge *0953

如果你要刪除tag: git tag -d release

好了,tag打好了,push這個tag;

使用git push 命令無法把這個tag提交到遠端倉庫中;

[email protected] MINGW64 /g/Git_learn/tt (master)
$ git push origin release
Counting objects: 1, done.
Writing objects: 100% (1/1), 152 bytes | 0 bytes/s, done.
Total 1 (delta 0), reused 0 (delta 0)
To [email protected]:topCoderzhangshuo/tt.git
* [new tag]         release -> release

當別人如果要使用這個tag程式碼可以:

[email protected] MINGW64 /g/Git_learn/newTest
$ git clone https://github.com/topCoderzhangshuo/tt.git
Cloning into 'tt'...
remote: Counting objects: 120, done.
remote: Compressing objects: 100% (9/9), done.
remote: Total 120 (delta 3), reused 0 (delta 0), pack-reused 111
Receiving objects: 100% (120/120), 64.76 KiB | 11.00 KiB/s, done.
Resolving deltas: 100% (12/12), done.
Checking connectivity... done.
[email protected] MINGW64 /g/Git_learn/newTest
$ cd tt/
[email protected] MINGW64 /g/Git_learn/newTest/tt (master)
$ git tag -l
release
[email protected] MINGW64 /g/Git_learn/newTest/tt (master)
$ git checkout release
Note: checking out 'release'.
You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by performing another checkout.
If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -b with the checkout command again. Example:
git checkout -b <new-branch-name>
HEAD is now at dee33c6... Merge branch 'issue1'
[email protected] MINGW64 /g/Git_learn/newTest/tt ((release))

在 Git 中你並不能真的檢出一個標籤,因為它們並不能像分支一樣來回移動。 如果你想要工作目錄與倉庫中特定的標籤版本完全一樣,可以使用 git checkout -b [branchname] [tagname] 在特定的標籤上建立一個新分支:

[email protected] MINGW64 /g/Git_learn/newTest/tt ((release))
$ git checkout -b releaseBranch release
Switched to a new branch 'releaseBranch'
[email protected] MINGW64 /g/Git_learn/newTest/tt (releaseBranch)

push tag 或者 push branch失敗:
error: src refspec release-1.0.1 matches more than one.

[email protected] MINGW64 /f/OMF (master)
$ git push origin release-1.0.1
error: src refspec release-1.0.1 matches more than one.
error: failed to push some refs to ‘https://**//OMF.git’

由於你的分支、tag有重名,產生
解決:


#git push origin refs/heads/release  指明推送分支
#git push origin refs/tag/release  指明推送tag
[email protected] MINGW64 /f/OMF (release)
$ git push origin refs/heads/release
Username for 
Total 0 (delta 0), reused 0 (delta 0)
To https://***/OMF.git
* [new branch]      release -> release