Git basic commands--tag, alias,

Source: Internet
Author: User
Tags tag name

git tag:

List labels

Listing existing tags in Git is simple and intuitive. You only need to enter git tag :

$ git tagv0. 1 v1. 3

This command lists the labels in alphabetical order, but the order in which they appear is not important.

You can also use a specific pattern to find tags. For example, Git's own source code warehouse contains more than 500 tags. If you are interested only in the 1.8.5 series, you can run:

$ 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
Create a label

Git uses two main types of tags: lightweight labels (lightweight) and note labels (annotated).

A lightweight tag is like a branch that doesn't change-it's just a reference to a specific commit.

However, the note tag is a complete object stored in a Git database. They can be verified, including the name of the tag, the e-mail address, the date time, and a label message, and the GNU Privacy Guard (GPG) signature and verification can be used. It is generally recommended to create a note tag so that you can have all of the above information, but if you just want to use a temporary tag, or for some reason you don't want to save that information, a lightweight label is also available.

Note Label

It's easy to create a sticky note tag in Git. The simplest way is to specify the options when you run the tag command -a :

$ git tag-a v1. 4 ' my version 1.4 ' $ git tagv0. 1 v1. 3 v1. 4

  -moption specifies a piece of information that will be stored in the label. If you don't specify a piece of information for the note label, Git runs the editor asking you to enter the information.

git showyou can see the tag information and the corresponding commit information by using the command:

$ git show v1.4Tag v1.4Tagger:ben Straub<[email protected]cc>Date:sat May3  -: +: A  the-0700my version1.4Commit Ca82a6dff817ec66f44342007202690a93763949author:scott Chacon<[email protected]>Date:mon Mar -  +: the: One  --0700changed the version number

The output shows the tag's information, the date and time of the tag, the note information, and then the specific submission information.

Light weight Label

Another way to label commits is to use a lightweight label. A lightweight label is essentially a commit checksum stored in a file-no additional information is saved. Create a lightweight label that does not require -a a use, -s or -m option, but only the tag name:

$ git tag v1. 4-lw$ git tagv0. 1 v1. 3 v1. 4 v1. 4-lwv1. 5

At this point, if you run on the label git show , you will not see additional tag information. The command will only display the submission information:

$ git show v1. 4-<[email protected]>Date:   £ º:  -0700    changed the version number
Post-hit labels

You can also tag past submissions. Suppose the commit history is this:

$ git log--pretty=oneline15027957951b64cf874c3557a0f3547bd83b3ff6 Merge Branch'Experiment'A6b4c97498bd301d84096da251c98a07c7723e65 beginningWritesupport0d52aaab4479697da7686c15f77a3d64d9165190 One Morething6d52a271eda8725415634dd79daabbc4d9b6008e Merge Branch'Experiment'0B7434D86859CC7B8C3D5E1DDDFED66FF742FCBC added a commitfunction4682c3261057305bdd616e23b64b0857d832627b added a todofile166ae0c4d3f420721acbb115cc33848dfcc2121a startedWriteSupport9fceb02d0ae598e95dc970b74767f19372d61af8 Updated RAKEFILE964F16D36DFCCDE844893CAC5B347E7B3D44ABBC Commit the todo8a5cbc430f1a9c3d00faaeffd07798508422908a updated readme

Now, let's say you forgot to label the project when you v1.2, which is the "updated Rakefile" submission. You can then make up the label. To tag on that commit, you need to specify the checksum (or partial checksum) of the commit at the end of the command:

$ git tag-a v1.29FCEB02 can see that you have tagged on that submission: $ git tagv0.1v1.2v1.3v1.4v1.4-Lwv1.5$ git show v1.2Tag v1.2Tagger:scott Chacon<[email protected]>Date:mon Feb9  the: +: -  the-0800version1.2Commit 9fceb02d0ae598e95dc970b74767f19372d61af8author:magnus Chacon<[email protected]>Date:sun APR -  -: +: *  --0700Updated Rakefile ...
Share tags

By default, the git push command does not transfer labels to the remote warehouse server. After you create the tag, you must explicitly push the label to the shared server. This process is like sharing a remote branch-you can run it git push origin [tagname] .

$ GIT push Origin v1.5Counting objects: -, Done. Delta compression using up to8threads.compressing objects: -% ( A/ A), Done. Writing objects: -% ( -/ -),2.05KiB |0BYTES/S, Done. Total -(Delta3), reused0(Delta0) to [email Protected]:schacon/Simplegit.git* [New tag] v1.5V1.5

If you want to push a lot of tags at once, you can also use --tags commands with options git push . This will send all the labels that are not on the remote repository server to that place.

$ GIT push origin--tagscounting objects:1, Done. Writing objects: -% (1/1), thebytes |0BYTES/S, Done. Total1(Delta0), reused0(Delta0) to [email Protected]:schacon/Simplegit.git* [New tag] v1.4V1.4* [New tag] v1.4-LW, v1.4-lw

Now, when other people clone or pull from the repository, they can also get your tags.

Check out labels

You can't really check out a tag in Git because they don't move back and forth like branches. If you want the working directory to be exactly the same as the specific label version in the warehouse, you can git checkout -b [branchname] [tagname] create a new branch using a specific label:

$ git checkout-b version2 v2. 0.0  'version2'

Of course, if you commit again after this, the version2 branch will move forward because of the change, then the version2 branch will be v2.0.0 slightly different from the label, then you should be careful.

and delete tags, rename, delete remote tags, etc.

git config:

Git aliases

Git does not automatically infer the commands you want when you enter some commands. If you don't want to enter the full Git command every time, you can git config easily set an alias for each command by using a file. Here are some examples you can try:

$ git config---------global alias.st status

This means that when you want to enter git commit , you only need to enter it git ci .

This technique can be useful when creating commands that you think should exist. For example, to resolve the ease-of-use problem of canceling a staging file, you can add your own cancellation staging alias to Git:

' Reset HEAD-- '

This causes the following two commands to be equivalent:

--FileA

A command is also usually added last , like this:

 $ git config--global alias. last    log-1 HEAD     This makes it easy to see the last commit: $ git  last  commit 66938dae3329c7aebe598c2246a8e6af90d04646author:josh Goebel  <[email  protected]>date:tue  26  Span style= "color: #800080;" >19 : 48 : 51  2008  +0800   Test  for  current head   signed -off-by:scott Chacon <[email protected]> 

As you can see, Git simply replaces the alias with the corresponding command. However, you might want to execute an external command instead of a GIT subcommand. If that's the case, you can add a symbol to the front of the command ! . It would be useful if you wanted to write some tools for collaborating with Git repositories. We now demonstrate the git visual aliases that will be defined gitk :

' !GITK '

There are also aliases, renaming, and so on.

Reference:

  Https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-%E6%89%93%E6%A0%87%E7%AD%BE

  Https://git-scm.com/book/zh/v2/Git-%E5%9F%BA%E7%A1%80-Git-%E5%88%AB%E5%90%8D

Git basic commands--tag, alias,

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.