1. Common (confused) commands - cold knowledge
- git commit opens the editor without -m self-service, which is used to enter comments for the change submission.
- git diff commit1 commit2 (commit1 is the benchmark)
- Git show branch -- more = 10 (view the commit summary information of the current branch)
- git mv file renaming
- git clone public_repo my_repo (the command can also create a complete copy of the original library public_repo locally)
- Git Rev parse 3b18e512 # view the full hash value of the object by prefix
2. git configuration
2.1 setting profile
git configuration file adopts ini text file. The location of the configuration file is different and the priority of the file is different, resulting in different actual scopes. (these configuration files may not exist and need to be created by yourself)
. git/config # (working directory) version library specific configuration, - file modify the configuration file, with the highest priority.
~/. gitconfig # (user root directory) user specific configuration, and the – global option modifies the configuration file.
/etc/gitconfig # system wide configuration file, - system modify the configuration file. (lowest priority)
For example, to create an author name and email address for all submissions of all version libraries. The corresponding profile modification command.
git config --global user.name "cyy"
git config --global user.email "cyy@163.com"
Another example: set a specific name and email address for a version library, overriding the – global setting.
git config user.name "cyy1"
git config user.email "cyy1@163.com"
2.2 view configuration file – git config -l
git config -l # lists the contents of the configuration file
cat .get/config # directly view the contents of the corresponding configuration file
2.3 remove profile settings – unset
git config --unset --global user.email # removes the global email settings.
2.3 command alias
If you often enter a common and responsible Git command, consider setting an alias for it. (by modifying the configuration file)
git commit --global alias show-graph 'log --graph --abbrev-commit --pretty=oneline'
#How graph is the alias of log -- graph -- abrev commit -- pretty = online command. The two functions are consistent
3.git object (git underlying operation command)
Object library is the core of git version control. The git object library contains four types of objects: blobs, trees, commit, and tags.
After initializing the version library, some template directories necessary for git are created. Generally, there is no need to operate or view Git directory.
3.1 initialize a version Library
chenyingying01@cyy git-test % mkdir hello chenyingying01@cyy git-test % cd hello chenyingying01@cyy hello % git init chenyingying01@cyy hello % find . . ./.git ./.git/config ./.git/objects # This directory is the directory where all Git objects are stored ./.git/objects/pack ./.git/objects/info ./.git/HEAD ./.git/info ./.git/info/exclude # .......
3.2 create a simple blob object
chenyingying01@cyy hello % echo "hello world" > hello.txt chenyingying01@cyy hello % ls -hl total 8 -rw-r--r-- 1 chenyingying01 staff 12B 8 28 11:35 hello.txt chenyingying01@cyy hello % git add hello.txt chenyingying01@cyy hello % find .git/objects .git/objects .git/objects/3b # The first byte of the hash value becomes a directory, which can improve the efficiency of the file system .git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad # Based on Hello Txt content calculation hexadecimal file name into the object library .git/objects/pack .git/objects/info
3.3 viewing file content based on hash value git cat file - P XXX
chenyingying01@cyy hello % git cat-file -p 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello world chenyingying01@cyy hello % git rev-parse 3b18e512 # View the full hash value of an object by prefix 3b18e512dba79e4c8300dd08aeb37f8e728b8dad
3.4 view file associations - git LS files - S
chenyingying01@cyy hello % git ls-files -s 100644 3b18e512dba79e4c8300dd08aeb37f8e728b8dad 0 hello.txt
3.5 creating git write tree for tree objects
Create file hash value - the corresponding list of file real names (forming a structure tree). The hash value of the tree is related to the content of the file list.
chenyingying01@cyy hello % git write-tree 68aba62e560c0ebc3396e8ae9335232cd93a3f60 chenyingying01@cyy hello % find .git/objects .git/objects .git/objects/68 .git/objects/68/aba62e560c0ebc3396e8ae9335232cd93a3f60 .git/objects/3b .git/objects/3b/18e512dba79e4c8300dd08aeb37f8e728b8dad .git/objects/pack .git/objects/info chenyingying01@cyy hello % git cat-file -p 68aba6 100644 blob 3b18e512dba79e4c8300dd08aeb37f8e728b8dad hello.txt
3.6 create the submission object git commit tree
chenyingying01@cyy hello % echo -n "commit a file that says hello\n" | git commit-tree 492413269 ff88f59f431c62619b961be4c27efb08506869de chenyingying01@cyy hello % git cat-file -p ff88f5 tree 492413269336d21fac079d4a4672e55d5d2147ac author chenyingying01 <chenyingying01@cyy.local> 1630212176 +0800 committer chenyingying01 <chenyingying01@cyy.local> 1630212176 +0800 commit a file that says hello
3.7 create tag git tag
(I don't know what a tag does) create a tag for a reference.
chenyingying01@cyy hello % git tag -m "Tag version 1.0" V1.0 49241326 # Annotated label chenyingying01@cyy hello % git rev-parse v1.0 # Hash value of tag a0f511a7c20b6ab5e6040dbc1e581b5c232bf3d6 chenyingying01@cyy hello % git cat-file -p a0f511 # View the content corresponding to the hash value object 492413269336d21fac079d4a4672e55d5d2147ac type tree tag V1.0 tagger chenyingying01 <chenyingying01@cyy.local> 1630212527 +0800 Tag version 1.0 chenyingying01@cyy hello %
In actual use, you should skip the lower git write tree and git coomit tree steps and only use the git commit command
Block (blob) – a file store named hash value
Directory tree – file hash value - corresponding list of file real names (forming a structure tree)
Commit –
Tag – don't know what it's for, and look down.