🎏 This is the 9th day of my participation in the Gwen Challenge. Check out the details: Gwen Challenge

0 x00 📢 preface

👇 Git getting started is linked below. Read the articles in that order at 👇.

Git goes from quitter to starter column

This series of articles explains how to quickly master the functions and operation flow of each command through examples to get started with Git.

Git command alias Settings, how to obtain the historical version, tag.

0 x01 alias

Make frequent Git commands simpler, easier, and more familiar by setting aliases.

Git status, git add, git commit, git checkout, git log The command is simple and easy to remember, and easy to enter, avoiding long parameter options.

Windows users

Set the alias using the git config command:

git config --global alias.co checkout git config --global alias.ci commit git config --global alias.st status git config  --global alias.br branch git config --global alias.hist"log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short"
git config --global alias.type 'cat-file -t'
git config --global alias.dump 'cat-file -p'
Copy the code

Unix/Mac users

Add the Settings to the.gitconfig file in the updated $HOME directory:

. . [alias]
    co = checkout
    ci = commit
    st = status
    br = branch
    hist = log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
    type = cat-file -t
    dump = cat-file -p
Copy the code

Git log Will change the default format when viewing logs. The command is too long to memorize.

$ git log --pretty=format:'%h %ad | %s%d [%an]' --graph --date=short
Copy the code

After setting the alias, you can do the same by typing git hist 👇.

0x02 Git Checkout Gets old version

usegit histThe (git log) command displays the history of the commit project and displays the hash of the commit snapshot for each version.

Checkout the specified version to the Working Directory with the git checkout

command.

Then check out the earliest version, view the submission history to obtain the hash value of the earliest submission 63120ae, and view the content of the file after the switchover.

$ git checkout 63120ae
$ cat helloworld.html 
Copy the code

helloworld.htmlThe content has been changed to the original.

Git checkout puts the repository in a “detached HEAD” state, which means that the HEAD (the part of the current directory that Git tracks should match) points directly to the commit rather than the branch. In the “split head pointer” state, if you make some changes and commit them, the label will not change, but your new commit will not belong to any branch and will not be accessible unless it is an exact commit hash. Therefore, if you need to make changes, such as fixing bugs in an older version, you usually need to create a new branch.

Switch to the latest version of the master branch

$ git checkout master
$ cat helloworld.html 
Copy the code

The Git checkout master command does two things. Restore the working directory to the snapshot that the master branch pointed to. At this point, the file content has changed to the last submission.

0x03 Git Tag Tag

Git can label a commit in the repository’s history as important. Use this feature to mark publication nodes.

Label the current version of the program as V1.

$ git tag v1
Copy the code

Previous version switch

If previous versions need to be checked out. Instead of a hash query, v1^ can be used to represent “last commit of version v1”. V1 to 1 can also be used, and the effect is the same. The value is in the format of tag to n. 1 can be replaced with any value of N.

$ git checkout v1^
$ cat helloworld.html 
Copy the code

Once checked out, mark the current version with a mark v1- RC.

$ git tag v1-rc
Copy the code

Enter git tag to list the existing tags.

$ git tag 
Copy the code

Check out the tag

Try switching between multiple tagged versions.

$ git checkout v1
$ git checkout v1-rc
$ git checkout v1
Copy the code

View labels in logs

Run the following command to view label information in the submission record.

$ git hist master --all
Copy the code

You can see two more tags in the logtag:v1 tag:v1-rc

0 x04 📚 reference

Pro Git Online

0x05 Attention column

This article has been included in the column 👇, you can directly follow.

Read more | The series continues to be updated