[Linux] Use of Linux command line git

forward is the only way
insert image description here



1. What is git?

1.
Git is an open source distributed version control system that can effectively and quickly handle project version management from small to very large. It is also an open source version control software developed by Linus Torvalds to help manage Linux kernel development.

2. To
put it bluntly, git is a software for project version management.

Two, gitee warehouse creation

1. New warehouse

1. There is a new warehouse in the upper right corner of the main interface of gitee
insert image description here
2. Configure the warehouse information
insert image description here

2. Copy the warehouse link

Click the HTTPS link in the orange button to copy the warehouse link

insert image description here

3. Clone the remote warehouse to the local

git clone+ warehouse link, you can clone the remote warehouse to the local

[wyn@VM-8-2-centos workdir]$ git clone https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git
Cloning into '12_27fordebug'...
Username for 'https://gitee.com': 15598303669
Password for 'https://[email protected]': 
remote: Enumerating objects: 6, done.
remote: Counting objects: 100% (6/6), done.
remote: Compressing objects: 100% (6/6), done.
remote: Total 6 (delta 0), reused 0 (delta 0), pack-reused 0
Unpacking objects: 100% (6/6), done.

Three, git submit code

1. Download git

sudo yum -y install git

2. Configure username and email (otherwise git commit cannot be used normally)

1. The following is the configured configuration information

git config --list // 查看git的配置列表

insert image description here
2. Configured globally, all local warehouses of ordinary users are valid, not just a certain warehouse.

git config --global user.name  "username"  // 名字缩写即可
git config --global user.email  "email"// 正常使用的邮箱

3. Modify your configuration information

git config --replace-all user.name "new-name"
git config --replace-all user.email "new-email"

4. Check the functions of other options of git config

[wyn@VM-8-2-centos 12_27fordebug]$ git config
usage: git config [options]

Config file location
    --global              use global config file
    --system              use system config file
    --local               use repository config file
    -f, --file <file>     use given config file
    --blob <blob-id>      read config from given blob object

Action
    --get                 get value: name [value-regex]
    --get-all             get all values: key [value-regex]
    --get-regexp          get values for regexp: name-regex [value-regex]
    --replace-all         replace all matching variables: name value [value_regex]
    --add                 add a new variable: name value
    --unset               remove a variable: name [value-regex]
    --unset-all           remove all matches: name [value-regex]
    --rename-section      rename section: old-name new-name
    --remove-section      remove a section: name
    -l, --list            list all
    -e, --edit            open an editor
    --get-color <slot>    find the color configured: [default]
    --get-colorbool <slot>
                          find the color setting: [stdout-is-tty]

Type
    --bool                value is "true" or "false"
    --int                 value is decimal number
    --bool-or-int         value is --bool or --int
    --path                value is a path (file or directory name)

Other
    -z, --null            terminate values with NUL byte
    --includes            respect include directives on lookup

3. Git submits code with three tricks

3.1 git add (add the code to the temporary area of ​​the local warehouse .git)

Using *, we can perform unified operations on the files with the suffix of the specified suffix at one time. For example, I will cut all the files with the suffix of .c and .h to the process directory, and then we can add the current directory to Inside the staging area of ​​the local warehouse .git.

[wyn@VM-8-2-centos workdir]$ mv *.c process
[wyn@VM-8-2-centos workdir]$ mv *.h process
[wyn@VM-8-2-centos 12_27fordebug]$ git add .

3.2 git commit -m (submit the code to the local warehouse .git)

add is added to the temporary area of ​​the warehouse, and commit is submitted to the local warehouse

[wyn@VM-8-2-centos 12_27fordebug]$ ll
total 24
-rw-rw-r-- 1 wyn wyn 9592 Dec 27 09:40 LICENSE
drwxrwxr-x 2 wyn wyn 4096 Dec 27 10:04 process
-rw-rw-r-- 1 wyn wyn  859 Dec 27 09:40 README.en.md
-rw-rw-r-- 1 wyn wyn  948 Dec 27 09:40 README.md
[wyn@VM-8-2-centos 12_27fordebug]$ git commit -m "这是第一次提交代码"

3.3 git push (synchronize the content of the local warehouse .git to gitee)

The so-called local warehouse is essentially a directory and its contents. The name of this directory is .git, and push to the remote end is to synchronize the contents of .git to gitee. After synchronization, there is actually a .git on gitee directory, but gitee does not allow us to see this directory.

[wyn@VM-8-2-centos 12_27fordebug]$ git push
Username for 'https://gitee.com': 15598303669
Password for 'https://[email protected]': 
Counting objects: 7, done.
Delta compression using up to 2 threads.
Compressing objects: 100% (4/4), done.
Writing objects: 100% (5/5), 584 bytes | 0 bytes/s, done.
Total 5 (delta 2), reused 0 (delta 0)
remote: Powered by GITEE.COM [GNK-6.4]
To https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git
   0f71a6a..1f9b73a  master -> master

4. Other extended git commands

1. What is the file .gitignore?

All files corresponding to the suffix inside this file will not be uploaded to gitee!

  [wyn@VM-8-2-centos 12_27fordebug]$ vim .gitignore 
  1 *.sln  添加了.sln后缀,作为.gitignore文件的改动
  2 # Prerequisites
  3 *.d
  4 
  5 # Compiled Object files
  6 *.slo
  7 *.lo
  8 *.o
  9 *.obj
 10 
 11 # Precompiled Headers
 12 *.gch
 13 *.pch
 14 
 15 # Compiled Dynamic libraries
 16 *.so
 17 *.dylib
 18 *.dll
 19 
 20 # Fortran module files
 21 *.mod                                                                                                                                                                 
 22 *.smod
 23 
 24 # Compiled Static libraries
 25 *.lai
 26 *.la
 27 *.a
 28 *.lib
 29 
 30 # Executables
 31 *.exe
 32 *.out
 33 *.app

2 git log (view git commit log)

[wyn@VM-8-2-centos process]$ git log
commit 64e37f98443db1be25ee2a34a4cef39b24db8602
Author: wyn <[email protected]>
Date:   Tue Dec 27 14:40:34 2022 +0800

    删除.txt后缀的文件

commit 1e28723cf0ef7d6b1ce5887df56e25655bd11748
Author: wyn <[email protected]>
Date:   Tue Dec 27 14:25:40 2022 +0800

    rename file

commit 02deaf907420261dc19fe61aba3acbf1ec422107
Author: wyn <[email protected]>
Date:   Tue Dec 27 14:18:51 2022 +0800

    修正了部分野指针的bug

commit d46c141392ab63ca70cdf545feec3a287e9a0177
Author: wyn <[email protected]>
Date:   Tue Dec 27 10:39:21 2022 +0800

    这是我的第一次提交

commit 14b1e1e46acdda069e87fbadaf6c0b3177dbeb80
Author: 举杯邀明月 <[email protected]>
Date:   Tue Dec 27 01:38:23 2022 +0000

    Initial commit

3 git status (check the status of the local warehouse)

1.
The modified content on line 7 means that we have just modified the content of the file .gitignore
Untracked on line 9 represents unmanaged files, which are files that are not in the warehouse

2.
After you have synchronized all the changed files in your local warehouse, the system will say that there is no commit, because you have already synchronized all the changes in the latest local warehouse to the remote warehouse

[wyn@VM-8-2-centos process]$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	modified:   ../.gitignore
#
# Untracked files:
#   (use "git add <file>..." to include in what will be committed)
#
#	Makefile
#	test.txt
no changes added to commit (use "git add" and/or "git commit -a")


[wyn@VM-8-2-centos 12_27fordebug]$ git status
# On branch master
nothing to commit, working directory clean

4 git mv + git rm (modify and delete files in the local warehouse)

[wyn@VM-8-2-centos process]$ git mv test.txt hello.txt
[wyn@VM-8-2-centos process]$ git rm -f hello.txt

All remote warehouses have been synchronized with the latest

insert image description here
insert image description here

5 git pull (pull the changes made by the remote warehouse to the local warehouse)

1.
First of all, we need to know that we can modify it in the remote warehouse

insert image description here
2.
If the remote warehouse has been modified, but it has not been synchronized to the local warehouse. At this time, if the local warehouse wants to continue to push the changes made by the local warehouse to the remote warehouse, an error will be reported directly, and the system will force us to synchronize the remote warehouse first. Modifications made by the end repository

[wyn@VM-8-2-centos 12_27fordebug]$ git push
Username for 'https://gitee.com': 15598303669
Password for 'https://[email protected]': 
To https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git
 ! [rejected]        master -> master (fetch first)
error: failed to push some refs to 'https://gitee.com/raise-your-glass-to-the-moon/12_27fordebug.git'
hint: Updates were rejected because the remote contains work that you do
hint: not have locally. This is usually caused by another repository pushing
hint: to the same ref. You may want to first merge the remote changes (e.g.,
hint: 'git pull') before pushing again.
hint: See the 'Note about fast-forwards' in 'git push --help' for details.

3.
All the changes we have to synchronize the remote warehouse to the local warehouse

[wyn@VM-8-2-centos 12_27fordebug]$ git pull

Guess you like

Origin blog.csdn.net/erridjsis/article/details/128444325