When we figure out how several git file states are, this part of the story becomes simple, and we'll look at a concrete example of how git modifies and modifies the restore. First create a new folder and set it to Git's factory via git init, add a a.txt file, and use git Add. After setting it to the staged state, add it to Git's repository by using git commit-m "first". These operations believe that we have mastered the proficiency of the.
Next we modify the A.txt file, execute git Add. Commit it to the staged state again, we don't commit, we write some content to a.txt, use git status to see the situation
We found that a.txt is in two states staged and modified, this is because we first modified the add after it became the staged state, index on the operation was recorded, but at this time after the modification, index found a.txt content and the repository is inconsistent, so it's like The modified state is changed to a commit operation at this time.
We found that the file only submitted the staged state of the changes, and the modified state of the file is not submitted, which proves again the contents of the previous lesson, only staged state to commit to the repository, if it is modified state, You need to set it to the staged state (that is, the staging area in the first lecture) by using Add. At this point, if I find that my changes are meaningless, I want a.txt to be consistent with the content in the repository, just use the following command
git checkout A.txt
Check out A.txt and we'll find that the file has the same content as the repository.
So through the checkout can be very convenient to let their files synchronize the content of the repository, note that the use of checkout can only synchronize the contents of the modified state, At this point we re-modify the A.txt, and after the operation through Add, A.txt file status from modified to staged state, we will use checkout to see the effect.
At this point we find that checkout is not able to restore the original file content (we will talk about Git's three common components in the next section, and then know why it cannot be restored). So we got a conclusion. The checkout command does not restore the contents of the staged state, at which point it can be
git reset HEAD a.txt
Set the file from the staged state to the modified state, which is to clear the file from the staging area.
You can then restore the content by using git checkout a.txt.
This lesson is here, as long as you have mastered several states of git, this content is very well understood. The next lecture will explain Git's core knowledge, which is the three most common components blob, Tree, and Commit of Git.