1. Three states of git:
Git has three states, and your files may be in one of them: committed, modified, and staged.
• Modified indicates that the file has been modified but not yet saved to the database.
• Staged means that the current version of a modified file is marked for inclusion in the next committed snapshot.
• Committed indicates that the data has been safely stored in the local database.
This will give our Git project three stages: the workspace, the staging area, and the Git directory.
git add
It is to submit the modified files in the workspace to the temporary storage area
git commit
It is to submit the files in the temporary storage area to the Git directory
Two, add back
1. If git add
after execution, it is found that a file has been added by mistake and submitted to the temporary storage area , you can use the following command to withdraw to the work area :
git reset HEAD <文件名>
2. If you want to withdraw all the files in the temporary storage area to the work area :
git reset HEAD
Three, commit rollback
1. git commit
After execution, if you want to cancel the submission for some reason but still keep the modification before commit, you can cancel the submission with the following command:
# 将暂存区最近一次提交到Git目录的文件全部撤回到暂存区
git reset --soft HEAD^
2. If you want to withdraw git commit
the sum git add
together:
# 将暂存区最近一次提交到Git目录的文件全部撤回到暂存区,且将暂存区的文件全部撤回到工作区
git reset --mixed HEAD^
# 等同于该命令
git reset --soft HEAD^ && git reset HEAD
3. If you don't want to keep all the changes submitted last time:
git reset --hard HEAD^