In principle, git has three different locations to save files locally.
Working tree: This represents all the files and folders you can see
index: This is actually saved in the .git folder like the following version library (the saving format is not discussed here)
Repository: Saves all submitted versions.
After everything is submitted, the latest submissions in WorkingTree, index area and repository are exactly the same.
git add 的意思是用 WorkingTree中的文件替换/更新index区中的文件。因此git add b.txt之后就是用当前保存的b.txtUpdate the b.txt file in index.
rm b.txt 仅仅是一条 linux 命令,就是删除文件的意思。对git来说这样只是在WorkingTree中删除了b.txt.
git commit 的意思是把 index 中的文件打包起来放入版本库。由于此时b.txt还在 index 区,所以git commit 仍旧会把b.txtUpdated to the repository.
Changes not staged for commit:
deleted: b.txt
This shows the difference between the current WorkingTree and the index area: The b.txt file has been deleted from the current WorkingTree, but the file still exists in the index.
no changes added to commit
This prompt should be said to be a warning, because git commit means to package the contents of the index area and put it into the repository. However, since it has been committed before and no new things have been added, the contents of the index area are the same as the latest submission. , there is no need for git to save again, so it displays "Nothing can be committed"
git rm The meaning of this command is to delete a certain file from the index area and WorkingTree, so after git rm b.txt it will no longer be in the indexgit rm 这条命令的意义是从index区和WorkingTree中删除某个文件,所以git rm b.txt之后index中就没有了b.txt. That’s it
git checkout <branch> means to update the contents of WorkingTree and index area with the latest commit in branch. Since it is irreversible, this command will give a prompt if the content in these two places has not been submitted to the repository. git checkout <branch> 的意思是用branch中最新的提交更新WorkingTree和index区中的内容。由于不可逆,所以如果这两个地方的内容没有提交到版本库的话这条命令会给出提示。 git checkout -- filename的意思是用index区的内容替换WorkingTree的某个文件--git checkout -- filename means to replace a file in WorkingTree with the content of the index area. -- is optional, indicating that everything after this parameter is the file name. . (Because sometimes the branch/tag may have the same name as the file)
An additional command is included. . . git status This means to show the difference between WorkingTree and index area (red by default), and the difference between index and the latest submitted version (green by default? Dark green?). In addition, there will be tips on how to update each other between them.
The questioner first needs to know why git needs the add operation. Because git only has the command line at the beginning, the add operation is equivalent to the file selection operation under the GUI, so the add and commit operations should be regarded as a whole (just like the GUI You can submit the file by selecting it below) and should not be separated.
1.git add b.txt //Add b.txt from the workspace to the stage 2.rm b.txt //Delete b.txt in the workspace, but do not execute git rm b. txt delete the file from the repository 3.git commit -m 'delete b.txt file'//Since git rm b.txt is not executed, commit only submits the content in 1 -->2,3 You should execute git rm b.txt to delete the file
I would like to remind you that modifying file names and deleting files in git are almost the same. As mentioned above, you need to use the git rm and git mv commands to operate respectively. There is a book called the authoritative guide to git. You can take a good look at it. Look
.Delete files: Delete a file in the workspace, rm file name There are two situations: The first case: the file needs to be deleted in the version library. git rm file name git commit -m 'description' Second case: accidentally delete the file git checkout -- file name
Newbie. . . Write some tutorials. . . . .
In principle, git has three different locations to save files locally.
Working tree: This represents all the files and folders you can see
index: This is actually saved in the
.git
folder like the following version library (the saving format is not discussed here)Repository: Saves all submitted versions.
After everything is submitted, the latest submissions in WorkingTree, index area and repository are exactly the same.
git add
的意思是用 WorkingTree中的文件替换/更新index区中的文件。因此git add b.txt
之后就是用当前保存的b.txt
Update the b.txt file in index.rm b.txt
仅仅是一条 linux 命令,就是删除文件的意思。对git来说这样只是在WorkingTree中删除了b.txt
.git commit
的意思是把 index 中的文件打包起来放入版本库。由于此时b.txt
还在 index 区,所以git commit
仍旧会把b.txt
Updated to the repository.This shows the difference between the current WorkingTree and the index area:
The
b.txt
file has been deleted from the current WorkingTree, but the file still exists in the index.This prompt should be said to be a warning, because
git commit
means to package the contents of the index area and put it into the repository. However, since it has been committed before and no new things have been added, the contents of the index area are the same as the latest submission. , there is no need for git to save again, so it displays "Nothing can be committed"git rm
The meaning of this command is to delete a certain file from the index area and WorkingTree, so aftergit rm b.txt
it will no longer be in the indexgit rm
这条命令的意义是从index区和WorkingTree中删除某个文件,所以git rm b.txt
之后index中就没有了b.txt
. That’s itgit checkout <branch>
means to update the contents of WorkingTree and index area with the latest commit in branch. Since it is irreversible, this command will give a prompt if the content in these two places has not been submitted to the repository.git checkout <branch>
的意思是用branch中最新的提交更新WorkingTree和index区中的内容。由于不可逆,所以如果这两个地方的内容没有提交到版本库的话这条命令会给出提示。git checkout -- filename
的意思是用index区的内容替换WorkingTree的某个文件--
git checkout -- filename
means to replace a file in WorkingTree with the content of the index area.--
is optional, indicating that everything after this parameter is the file name. . (Because sometimes the branch/tag may have the same name as the file)An additional command is included. . .
git status
This means to show the difference between WorkingTree and index area (red by default), and the difference between index and the latest submitted version (green by default? Dark green?). In addition, there will be tips on how to update each other between them.try
git rm filename
The questioner first needs to know why git needs the add operation. Because git only has the command line at the beginning, the add operation is equivalent to the file selection operation under the GUI, so the add and commit operations should be regarded as a whole (just like the GUI You can submit the file by selecting it below) and should not be separated.
1.git add b.txt //Add b.txt from the workspace to the stage
2.rm b.txt //Delete b.txt in the workspace, but do not execute git rm b. txt delete the file from the repository
3.git commit -m 'delete b.txt file'//Since git rm b.txt is not executed, commit only submits the content in 1
-->2,3 You should execute git rm b.txt to delete the file
I would like to remind you that modifying file names and deleting files in git are almost the same. As mentioned above, you need to use the git rm and git mv commands to operate respectively. There is a book called the authoritative guide to git. You can take a good look at it. Look
.Delete files:
Delete a file in the workspace, rm file name
There are two situations:
The first case: the file needs to be deleted in the version library.
git rm file name
git commit -m 'description'
Second case: accidentally delete the file
git checkout -- file name
One less git rm added in front