Chapter 3 Git Common Commands

3.1 Set user signature

1) Basic grammar

git config --global user.name username

git config --global user.email mailbox

2) Case Practice

Signature settings at global scope:

​
Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git config --global user.name Layne

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git config --global user.email [email protected]

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ cat ~/.gitconfig

[user]

name = Layne

email = [email protected]

illustrate:

The function of the signature is to distinguish different operator identities. The user's signature information can be seen in the submission information of each version

to confirm who made the commit. Git must be installed for the first time to set up a user signature, otherwise the code cannot be submitted.

※Note: There is nothing to set the user signature here and the account to log in to GitHub (or other code hosting centers) in the future.

what relationship.

3.2 Initialize the local library

1) Basic grammar

git init

2) Case Practice

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720

$ git init

Initialized empty Git repository in D:/Git-Space/SH0720/.git/

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ ll -a

total 4

drwxr-xr-x 1 Layne 197609 0 11 月 25 14:07 ./

drwxr-xr-x 1 Layne 197609 0 11 月 25 14:07 ../

drwxr-xr-x 1 Layne 197609 0 Nov 25 14:07 .git/ (effect of .git initialization, generate git)

3) View the results

3.3 View the status of the local library

1) Basic grammar

git status

2) Case Practice

3.3.1 View for the first time (there is no file in the workspace)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

No commits yet

nothing to commit (create/copy files and use "git add" to track)

3.3.2 New file (hello.txt)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ vim hello.txt

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

3.3.3 Look again (untracked files detected)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

No commits yet

Untracked files:

(use "git add ..." to include in what will be committed)

hello.txt

nothing added to commit but untracked files present (use "git add"

to track)

3.4 Add a staging area

3.4.1 Add the files in the workspace to the temporary storage area

1) Basic grammar

git add filename

2) Case Practice

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git add hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory.

3.4.2 View status (new files detected in the temporary storage area)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

No commits yet

Changes to be committed:

(use "git rm --cached ..." to unstage)

new file: hello.txt

3.5 Submit the local library

3.5.1 Submit the files in the temporary storage area to the local library

1) Basic grammar

git commit -m "log information" file name

2) Case Practice

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git commit -m "my first commit" hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working

directory.

[master (root-commit) 86366fa] my first commit

1 file changed, 16 insertions(+)

create mode 100644 hello.txt

3.5.2 View status (no files need to be submitted)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

nothing to commit, working tree clean

3.6 Modify the file (hello.txt)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ vim hello.txt

hello git! hello atguigu! 2222222222222

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

3.6.1 Check the status (it is detected that a file in the workspace has been modified)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

Changes not staged for commit:

(use "git add ..." to update what will be committed)

(use "git checkout -- ..." to discard changes in working

directory)

modified: hello.txt

no changes added to commit (use "git add" and/or "git commit -a")

3.6.2 Add the modified file to the temporary storage area again

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git add hello.txt

warning: LF will be replaced by CRLF in hello.txt.

The file will have its original line endings in your working directory.

3.6.3 Check the status (the modification of the workspace has been added to the temporary storage area)

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git status

On branch master

Changes to be committed:

(use "git reset HEAD ..." to unstage)

modified: hello.txt

3.7 Historical versions

3.7.1 View historical versions

1) Basic grammar

git reflog view version information

git log view version details

2) Case Practice

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git reflog

087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commit

ca8ded6 HEAD@{1}: commit: my second commit

86366fa HEAD@{2}: commit (initial): my first commit

3.7.2 Version Shuttle

1) Basic grammar

git reset --hard version number

2) Case Practice

-- First check the current history, you can see that the current version is 087a1a7

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git reflog

087a1a7 (HEAD -> master) HEAD@{0}: commit: my third commit

ca8ded6 HEAD@{1}: commit: my second commit

86366fa HEAD@{2}: commit (initial): my first commit

--Switch to version 86366fa, which is the version we submitted for the first time

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git reset --hard 86366fa

HEAD is now at 86366fa my first commit

-- Check the history after the switch is complete, the current successful switch to the 86366fa version

Layne@LAPTOP-Layne MINGW64 /d/Git-Space/SH0720 (master)

$ git reflog

86366fa (HEAD -> master) HEAD@{0}: reset: moving to 86366fa

087a1a7 HEAD@{1}: commit: my third commit

ca8ded6 HEAD@{2}: commit: my second commit

86366fa (HEAD -> master) HEAD@{3}: commit (initial): my first commit

-- Then check the file hello.txt and find that the content of the file has changed

$ cat hello.txt

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

hello git! hello atguigu!

When Git switches versions, the bottom layer is actually a moving HEAD pointer. The specific principle is shown in the figure below.

Guess you like

Origin blog.csdn.net/wzw_wwl/article/details/126221709