The principle and use of Git tools -- basic use

The principle and use of Git tools – basic use

1. Create a local warehouse

git init

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git init
Initialized empty Git repository in /home/Lxy/gitcode/.git/
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ la
bash: la: command not found
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ ll -a
total 12
drwxrwxr-x  3 Lxy Lxy 4096 Jun 25 20:52 .
drwx------ 13 Lxy Lxy 4096 Jun 25 20:52 ..
drwxrwxr-x  7 Lxy Lxy 4096 Jun 25 20:52 .git

2. Configure the local warehouse

Add configuration name and email address, if there are no these two configurations, an error may be reported

Add configuration name and email

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git config user.name "Lxy"
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git config user.email "[email protected]"

view configuration

git config -l

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git config -l
user.email=2357246060@qq.com
user.name=Yaulixingyu
push.default=current
credential.helper=store
core.repositoryformatversion=0
core.filemode=true
core.bare=false
core.logallrefupdates=true
user.name=Lxy
user.email=2357246060@qq.com

Reset/delete a configuration

git config --unset ...

git config --unset user.name

global attribute

Adding the global attribute means: this configuration item will take effect in all local warehouses in this server

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git config --global user.name "Lxy"
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git config --global user.email "[email protected]"

remove the global attribute

git config --global --unset [属性字段]

3. Understand the work area, temporary storage area, and version library

We gitcodecreate a ReadMefile inside the current file, so ReadMecan this be managed by git? The answer is no!

In order to understand this truth, we need to understand a few concepts.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ touch ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ ll
total 0
-rw-rw-r-- 1 Lxy Lxy 0 Jun 25 21:07 ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ ll -a
total 12
drwxrwxr-x  3 Lxy Lxy 4096 Jun 25 21:07 .
drwx------ 13 Lxy Lxy 4096 Jun 25 21:01 ..
drwxrwxr-x  7 Lxy Lxy 4096 Jun 25 21:03 .git
-rw-rw-r--  1 Lxy Lxy    0 Jun 25 21:07 ReadMe

We also do not run manually modifying files (adding, deleting, etc.) .gitunder . Therefore, the file can only be ReadMewritten in the current path. Then this area we call the work area . and .gitis called a repository.

Workspace : is the directory on your computer where you want to write code or files

Repository : Also known as warehouse, there is a hidden directory in the workspace .git. It is not considered a workspace, but a Git repository. All the files in this version library can be managed by Git. Git can track the modification and deletion of each file, so that the history can be tracked at any time, or can be restored at some point in the future.

Temporary storage area : generally stored in .gitthe index file on the directory, we sometimes call the temporary storage area index

insert image description here

-- 不允许在.git下手动修改
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ tree .git
.git
├── branches
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── info
│   └── exclude
├── objects
│   ├── info
│   └── pack
└── refs
    ├── heads
    └── tags

9 directories, 13 files

insert image description here

This diagram shows the relationship between workspace, staging area and repository.

  • The left side of the figure is the workspace, and the right side is the repository. There are many things stored in the Git repository, the most important of which is the temporary storage area.

  • When creating a Git repository, Git will automatically create a unique master branch for us, and a pointer to the master called HEAD.

  • When the git add command is executed on files modified (added or deleted) in the workspace , the file index of the directory tree in the temporary storage area will be updated.

  • When the commit operation git commit is performed, the master branch will be updated accordingly, which can be simply understood as the directory tree in the temporary storage area will be actually written into the repository.

The essence of git add is to add the code of the workspace to the temporary storage area; the essence of git commit is to add the directory tree of the temporary storage area to the master.

**Note:** Adding or pasting files into the directory does not mean adding files to the warehouse, but just adding files to the workspace. Files must git add 和 git commitbe added to the repository for management by using commands! ! !

Both the temporary storage area and the master store are directory indexes, and the modified workspace content will be written into .git/objectsa new git object in the object library ( ).

4. Add files – scene one

Now we want git to manage ReadMethe file, we use the git add command to add the file to the temporary storage area:

  • Add one or more files to the staging area:git add [file1] [file2]...
  • Add the specified directory to the staging area, including subdirectories:git add [dir]
  • Add all file changes in the current directory to the temporary storage area:git add .

Then use git committhe command to add the contents of the staging area to the local warehouse:

  • Add all the contents of the staging area to the local warehouse:git commit -m "message"
  • Submit the specified file in the temporary storage area to the warehouse:git commit [file1] [file2] ... -m "message"

Note: git commitThe following -m option must keep up with the message describing this submission, which is completed by the user. This part of the content must not be omitted, and it must be described well. It is used to record your submission details and is for us. People see it.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git add ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git commit -m 'add first file'
[master (root-commit) 3b64204] add first file
 1 file changed, 1 insertion(+)
 create mode 100644 ReadMe

git commitAfter the command is successfully executed, it will tell us that 1 file has been changed (that is, our newly added ReadMefile). We can also add different files multiple times, and submit all the files with only one commit, because all the files that need to be submitted are added to the temporary storage area, and then all the changes in the temporary storage area are committed at one time.

git log

You can use git logthe command to view the historical submission records

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git log
commit 3b64204395259ee23740455b39ef6282195666d7
Author: Lxy <2357246060@qq.com>
Date:   Sun Jun 25 21:36:12 2023 +0800

    add first file

This command displays the commit log from the latest to the farthest, and you can see the log message when we commit. If you think the output information is too much, you can try to add --pretty=oneline parameters.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git log --pretty=oneline
3b64204395259ee23740455b39ef6282195666d7 add first file

Explain:

What we see 3b64204395259ee23740455b39ef6282195666d7is similar to the (version number) of each submission commit id. Git commit idis not an incremental number of 1, 2, 3..., but a SHA1(安全哈希算法)calculated very large number expressed in hexadecimal.

5. View .gitfiles

Let's use tree .git to see the directory structure of .git:

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ tree .git
.git
├── branches
├── COMMIT_EDITMSG
├── config
├── description
├── HEAD
├── hooks
│   ├── applypatch-msg.sample
│   ├── commit-msg.sample
│   ├── post-update.sample
│   ├── pre-applypatch.sample
│   ├── pre-commit.sample
│   ├── prepare-commit-msg.sample
│   ├── pre-push.sample
│   ├── pre-rebase.sample
│   └── update.sample
├── index
├── info
│   └── exclude
├── logs
│   ├── HEAD
│   └── refs
│       └── heads
│           └── master
├── objects
│   ├── 0e
│   │   └── 6b1780b73cd9220ec5073dc64b42f7ad4bd945
│   ├── 3b
│   │   └── 64204395259ee23740455b39ef6282195666d7
│   ├── 8d
│   │   └── 0e41234f24b6da002d962a26c2495ea16a425f
│   ├── info
│   └── pack
└── refs
    ├── heads
    │   └── master
    └── tags

15 directories, 21 files
  • indexIt is the temporary storage area, and the content after add is added here
  • HEADIt is the pointer to the master branch by default
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat .git/HEAD
ref: refs/heads/master
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat .git/refs/heads/master 
3b64204395259ee23740455b39ef6282195666d7

After finding this file, we generally cannot directly see what is inside. This type of file is encrypted by sha (secure hash algorithm). Fortunately, we can use the git cat-file (-p option to change the output format. For viewing) command to view the contents of the repository object:

What is printed 3b64204395259ee23740455b39ef6282195666d7is the latestcommit id

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git cat-file -p 3b64204395259ee23740455b39ef6282195666d7
tree 0e6b1780b73cd9220ec5073dc64b42f7ad4bd945
author Lxy <2357246060@qq.com> 1687700172 +0800
committer Lxy <2357246060@qq.com> 1687700172 +0800

add first file

The content of the tree is the commit id

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git cat-file -p 0e6b1780b73cd9220ec5073dc64b42f7ad4bd945
100644 blob 8d0e41234f24b6da002d962a26c2495ea16a425f	ReadMe

And 8d0e41234f24b6da002d962a26c2495ea16a425fwhat is this line? What we found was the most recent modification

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git cat-file -p 8d0e41234f24b6da002d962a26c2495ea16a425f
hello git
  • objects It is the object library of Git, which contains various version library objects and contents created. When the git add command is executed, the directory tree in the temporary storage area is updated, and the modified (or newly added) file content in the work area is written to a new object in the object library, which is located at " .git/objects" directory, let's see what these objects are used for:
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ ls .git/objects/
0e  3b  8d  info  pack

To sum up: In the local git warehouse, there are several files or directories that are very special

  • index: Temporary storage area, the content will be updated after git add
  • HEAD: A pointer to the master branch by default
  • refs/heads/master: save masterthe latest version of the current branch in the filecommit id
  • objects: Contains various version library objects and contents created, which can be simply understood as putting all the modifications maintained by git.

6. Add files – scene two

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ touch file1
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git add file1
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ touch file2
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git commit -m "add file"
[master cfd11ac] add file
 1 file changed, 0 insertions(+), 0 deletions(-)
 create mode 100644 file1

First, we add a new file1file and add the file to the temporary storage area; then add a new file2file, and at this time we commit to submit the modification. We found that printing after submitting 1 file changed, 0 insertions(+), 0 deletions(-)means that only one file has changed. Didn’t we add two new files at this time?

In fact, this problem is also relatively easy to understand, because git addit is to add the file to the temporary storage area, git commitand add the content of the temporary storage area to the local warehouse. Since we have not used it, it is not git add file2,file2in the temporary storage area, so when we commit, it is actually just The submissions that are already in the temporary storage area file1are submitted, but the work area is omitted file2. And if we want to submit again file2, we only need to add and commit again.

7. Modify the file

What is modification?

For example, we add a new line, delete a line, change some characters, or even create a new file, which are all modifications.

Git tracks changes, not files

For example, we ReadMemake a modification (add) to the file

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat ReadMe 
hello git
hello world
hello ReadMe

At this point, the ones in the warehouse are different from ReadMethose in our workspace . We can use commands to check whether the files have been modified again since your last submission.ReadMegit status

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ 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:   ReadMe
#
no changes added to commit (use "git add" and/or "git commit -a")

The above result tells us that ReadMeit has been modified, but the addition and submission have not been completed.

At present, we only know that the file has been modified. It would be better if we can know the specific places that have been modified.

Therefore, we can use git diff [file]the command to display the difference between the temporary storage area and the workspace file. The displayed format is the common diff format of Unix, and we can also use the git diff HEAD -- [file]command to view the difference between the repository and the workspace file.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git diff ReadMe
diff --git a/ReadMe b/ReadMe
index 8d0e412..8c2b72f 100644
--- a/ReadMe
+++ b/ReadMe
@@ -1 +1,3 @@
 hello git
+hello world
+hello ReadMe

The ones with + in front of them are the new content we added this time.

After knowing ReadMewhat changes have been made, it is much more at ease to submit it to the local warehouse.

8. Version rollback

Git can manage the historical version of the file, which is also an important capability of the version controller. If one day we find that there is a big problem with the previous work and we need to start over in a specific historical version, at this time, we need the function of version rollback.

The execution git resetcommand is used to roll back the version, and you can specify to roll back a submitted version.

The essence of 'rollback' is to roll back the content in the version library. Whether the work area or the temporary storage area is rolled back is determined by the command parameters:

git resetCommand syntax format:git ret [--soft | --mixed | --hard] [HEAD]

  • --mixed: It is the default option, which can be used without this parameter. This parameter will return the content of the temporary storage area to the content of the specified submitted version, and the workspace file will remain unchanged.
  • --soft: The parameters are unchanged for the content of the work area and the temporary storage area, but the version is rolled back to a specified version.
  • --hard: The parameter returns both the staging area and the working area to the specified version. Remember not to use this command when the workspace contains uncommitted code, because the workspace will be rolled back, and the code you have not submitted will never be retrieved, so use it with caution.
  • HEAD Description:
    • You can directly Ctrip commit id, indicating the specified rollback version
    • HEAD indicates the current version
    • HEAD ^ previous revision
    • HEAD ^^ Previous version
    • And so on...
  • You can use the ~ number to represent:
    • HEAD ~ 0 indicates the current version
    • HEAD ~ 1 previous revision
    • HEAD ~ 2 last revision
    • And so on...

In order to facilitate the expression and test the rollback function, we first do some preparatory work: update the 3 versions ReadMeand make 3 submissions respectively, as follows:

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git log --pretty=oneline
2f86525112a4c8d08431fbf0c66110169acc28f7 第三次修改ReadMe
02716a930c61d73454ca22e8096af38c6059aab2 修改ReadMe
0c3e2b8c6d56bb935a38692d958ea21bf983aa4a add file2
cfd11ac69dd517ec96fff4d1119b617a1f90f55d add file
3b64204395259ee23740455b39ef6282195666d7 add first file

Now, if we want to roll back to the previous version and re-write based on the previous version, since we want the content of the workspace to roll back to the previous version, we use parameters here --hard.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git log --pretty=oneline
2f86525112a4c8d08431fbf0c66110169acc28f7 第三次修改ReadMe
02716a930c61d73454ca22e8096af38c6059aab2 修改ReadMe
0c3e2b8c6d56bb935a38692d958ea21bf983aa4a add file2
cfd11ac69dd517ec96fff4d1119b617a1f90f55d add file
3b64204395259ee23740455b39ef6282195666d7 add first file
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git reset --hard 02716a930c61d73454ca22e8096af38c6059aab2
HEAD is now at 02716a9 修改ReadMe

At this point we found that ReadMethe content of the file has been rolled back.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat ReadMe 
hello git
hello world
hello ReadMe

We git logchecked the log again and found HEADthat it pointed to the previous version.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git log --pretty=oneline
02716a930c61d73454ca22e8096af38c6059aab2 修改ReadMe
0c3e2b8c6d56bb935a38692d958ea21bf983aa4a add file2
cfd11ac69dd517ec96fff4d1119b617a1f90f55d add file
3b64204395259ee23740455b39ef6282195666d7 add first file

So far we have demonstrated the rollback function, but if I regret it now and want to go back to the latest version, what should we do? We can continue to use git resetthe command to roll back to the latest version, but we must get his commit id. But we git logcan't print out that one time commit id. If we are lucky, we can find it from the previous records of the terminal. But if you are unlucky, this commit id has been lost by us.

Therefore, Git also provides a git reflogcommand to remedy this, which is used to record every local command:

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git reflog
02716a9 HEAD@{
    
    0}: reset: moving to 02716a930c61d73454ca22e8096af38c6059aab2
2f86525 HEAD@{
    
    1}: commit: 第三次修改ReadMe
02716a9 HEAD@{
    
    2}: commit: 修改ReadMe
0c3e2b8 HEAD@{
    
    3}: commit: add file2
cfd11ac HEAD@{
    
    4}: commit: add file
3b64204 HEAD@{
    
    5}: commit (initial): add first file

In this way, we can easily find all the operation records. But 2f86525what? This is part of the commit id of the latest version. Therefore, when the Git version is rolled back, parts can also be used commit idto represent the target version.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git reset --hard 2f86525
HEAD is now at 2f86525 第三次修改ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git log --pretty=oneline
2f86525112a4c8d08431fbf0c66110169acc28f7 第三次修改ReadMe
02716a930c61d73454ca22e8096af38c6059aab2 修改ReadMe
0c3e2b8c6d56bb935a38692d958ea21bf983aa4a add file2
cfd11ac69dd517ec96fff4d1119b617a1f90f55d add file
3b64204395259ee23740455b39ef6282195666d7 add first file

It is worth mentioning that Gitthe rollback speed of the version is very fast, because Git has a pointer to the current branch (here master) internally HEAD, and the latest version of the current branch refs/heads/masteris saved in the file . When we roll back the version, we just store a specific version in . The schematic diagram is as follows:master commit idGitrefs/heads/master

insert image description here

9. Undo modification

If we have written code in our workspace for a long time, we are not satisfied with this code and want to restore to the previous version. Then we have to undo the operation.

Situation 1: For the code in the workspace, there is no add

Of course, you can directly delete the code you have added in the workspace. But if we have written for a long time and have not submitted it, how should we delete it?

Git provides us with a better way, we can use git checkout -- [file]commands to return the files in the workspace to the state of the last add or commit. It is very important to pay attention to git checkout -- [file]the – in the command, remember not to omit it.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ vim ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat ReadMe 
hello git
hello world
hello ReadMe

git --version

git --version 2  # 新增的一行代码
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ 

We use git checkout -- ReadMeto restore to the last add or commit

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git checkout -- ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat ReadMe
hello git
hello world
hello ReadMe

git --version

Situation 2: already added, but no commit

Is it still in the temporary storage area after add? How to undo it?

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ vim ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat ReadMe 
hello git
hello world
hello ReadMe

git --version

git --version 2 #新增了一行代码
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git add ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	modified:   ReadMe
#

We can use git resetthe rollback command. If the command uses --mixedparameters, the content of the temporary storage area can be rolled back to the unspecified version content, but the workspace file remains unchanged, then we can roll back the content of the temporary storage area!

--mixedis the default parameter and can be omitted when using

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git reset HEAD ReadMe
Unstaged changes after reset:
M	ReadMe

Use git statusit to check and find that the temporary storage area is clean now, and the work area has been modified

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ 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:   ReadMe
#
no changes added to commit (use "git add" and/or "git commit -a")

So far, it has been recovered. Our modification only exists in the workspace. If you want to restore the content of the workspace, you will return to situation 1.

Situation 3: Added and committed

In this case, we can git reset --hard HEAD^roll back to the previous version! However, this is conditional, that is, you have not pushed your local version library to the remote. Git is a distributed version control system. Once you push to the remote version library, it is difficult to handle... [There is no push operation after commit]

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git add ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git commit -m "新增ReadMe"
[master 5bc172f] 新增ReadMe
 1 file changed, 2 insertions(+)
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git status
# On branch master
nothing to commit, working directory clean
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git reset --hard HEAD^
HEAD is now at 2f86525 第三次修改ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ cat ReadMe 
hello git
hello world
hello ReadMe

git --version

The purpose of revocation: is not to affect the remote warehouse.

10. Delete files

In Git, deletion is also a modification operation. If we want to delete ReadMea file, what should we do? If we pass rm ReadMethe command, we just delete the files in the workspace ReadMe, but not in the version library. Therefore, it is useless to delete directly in this way, but it will only increase troubles. Order git statusHui to immediately tell you that those files are deleted up.

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ rm ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git status
# On branch master
# Changes not staged for commit:
#   (use "git add/rm <file>..." to update what will be committed)
#   (use "git checkout -- <file>..." to discard changes in working directory)
#
#	deleted:    ReadMe
#
no changes added to commit (use "git add" and/or "git commit -a")

At this time, the workspace and the version library are not consistent. To delete files, in addition to deleting the files in the workspace, you must also clear the files in the version library. There are generally two situations:

  • Do you want to delete the file from the repository
  • accidentally deleted

For the second case, it is obvious that it was deleted by mistake and needs to be restored using git. We directly usegit checkout -- ReadMe

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git checkout -- ReadMe
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ ll
total 4
-rw-rw-r-- 1 Lxy Lxy  0 Jun 26 12:19 file1
-rw-rw-r-- 1 Lxy Lxy  0 Jun 26 12:19 file2
-rw-rw-r-- 1 Lxy Lxy 50 Jun 26 13:46 ReadMe

For the first case, it is obvious that we have not finished deleting. We just deleted the files in the workspace. At this time, we need to delete git rmthe files from the temporary storage area and the workspace, and commit:

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git rm file1
rm 'file1'
[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git status
# On branch master
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#	deleted:    file1
#

If we want to delete file1the file here, we only need to commit in the end

[Lxy@iZ0jl0hb8whfvf16k6pumcZ gitcode]$ git commit -m "delete file1"
[master 7804665] delete file1
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 file1

The file is now removed from the repository.

Guess you like

Origin blog.csdn.net/qq_58325487/article/details/131395903