git common commands 3

Playing tag in Git is very simple, first of all, to tag the switch to branch:

$ git branch
* dev
  master
$ git checkout master
Switched to branch 'master'

Then, knock command git tag <name>you can play a new label:

$ git tag v1.0

You can use the command git tagto see all tags:

$ git tag
v1.0

The default labels are playing in the commit latest submitted. Sometimes, if you forget to tag, for example, it is now Friday, but did not play in Monday's fight should be a label, how do?

The method is to find the commit id history submitted, and then marked on it:

$ 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 & simple 14096d0 AND simple b17d20e branch test d46f35e remove test.txt b84166e add test.txt 519219b git tracks changes e43a48b understand how stage works 1094adb append GPL e475afc add distributed eaadf4e wrote a readme file 

Let's say you want to add mergesubmit this to play tag, which corresponds to commit id Shi f52c633, typing the command:

$ git tag v0.9 f52c633

Then the command git tagView Tags:

$ git tag
v0.9
v1.0

Note that the label is not listed in chronological order, but in alphabetical order. You can git show <tagname>view the label information:

$ git show v0.9
commit f52c63349bc3c1593499807e5c8e972b82c8f286 (tag: v0.9) Author: Michael Liao <[email protected]> Date: Fri May 18 21:56:54 2018 +0800 add merge diff --git a/readme.txt b/readme.txt ... 

You can see, v0.9it is indeed playing in add mergethis submission.

You can also create a label with instructions, with -athe specified tag name, -mspecify the caption:

$ git tag -a v0.1 -m "version 0.1 released" 1094adb 

Command git show <tagname>can see the caption:

$ git show v0.1
tag v0.1
Tagger: Michael Liao <[email protected]>
Date:   Fri May 18 22:48:43 2018 +0800

version 0.1 released

commit 1094adb7b9b3807259d8cb349e7df1d4d6477073 (tag: v0.1)
Author: Michael Liao <[email protected]>
Date:   Fri May 18 21:06:15 2018 +0800

    append GPL

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

If the label is wrong, you can also delete:

$ git tag -d v0.1
Deleted tag 'v0.1' (was f15b0dd) 

Because the label created only stored locally are not automatically pushed to the remote. Therefore, the wrong label can delete the local security.

If you want to push a label to the remote, use the command git push origin <tagname>:

$ git push origin v1.0
Total 0 (delta 0), reused 0 (delta 0) To github.com:michaelliao/learngit.git * [new tag] v1.0 -> v1.0 

Alternatively, a one-time push has not been pushed to all remote local label:

$ git push origin --tags
Total 0 (delta 0), reused 0 (delta 0) To github.com:michaelliao/learngit.git * [new tag] v0.9 -> v0.9 

If the tag has been pushed to the remote, remote tag you want to remove a little trouble, delete start local:

$ git tag -d v0.9
Deleted tag 'v0.9' (was f52c633) 

Then, remove from the remote. Delete command also push, but the format is as follows:

$ git push origin :refs/tags/v0.9
To github.com:michaelliao/learngit.git - [deleted] v0.9

Guess you like

Origin www.cnblogs.com/liufei-90046109/p/11302557.html