preface
It was a little illogical to have to commit unfinished work once in note 5 because you had to deal with an urgent problem. Isn’t there another way? The answer is definitely yes, we know from learning C language that local variables are stored in the stack, in Git we do not complete the work can also be temporarily stored in the stack.
Git storage
You don’t want to commit to the branch just because you leave it for a short time, so you should take advantage of the commands that Git stores.
The command
- Git Stash puts unfinished changes on a stack.
- Git Stash list to see what is stored.
- Git stash apply Stash @{number} reapplies to the store that the number points to, but this command does not delete the store.
- Git stash stash@{number} Delete the storage that the number points to.
- Git Stash pop Applies the storage at the top of the stack and removes it.
Blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah blah
Summary: Using git statsh is really not committed? The answer is definitely not commit, but Git sent me automatically commit ~
Git retreat
Review what we have learned about Git related operations seems to be a rush forward!! There is no undo operation, so let’s look at the undo operation. First of all, we write code in the workspace, staging area, and repository, so we do undo around these three areas (assuming the file is already tracked by Git).
Withdrawal of work area
Workspace undo is to undo changes made in the working directory (actually c-Z can do this hahaha).
-
Git restore fileName
Withdrawal of staging area
Withdrawal of the staging area is the withdrawal of the content that has been put into the staging area.
-
Git restore –staged fileName Shown above
A repository withdrawal
Repository retraction is the retraction of content that has already been committed or the modification of information added at the time of the commit.
-
Git commit –amend
In addition to the error in the submission information, it is a kind of error, for example: suppose jC.txt has been added to the staging area, at this time we modify jC.txt but do not re-join the staging area and then commit the operation, so that the jC.txt in the final submission object will have a problem. The first way is to add jC.txt to the temporary storage again to commit and write comments, etc. The second way is to use git commit –amend command, without saying anything directly to the above picture.
Git retreats
Through the above learning we can have a certain understanding of Git retreat, but this is far from enough, the following is its principle to analyze.
Reset related commands
-
Git reset –soft HEAD~ Moves the branch pointed to by the HEAD. This is different from the checkout command. Checko moves the HEAD and does not move the branch executed by the HEAD. Go straight to the picture
After reading this illustration, you will understand. Be sure to try it yourself!
-
Git reset –mixed HEAD~ git reset –mixed HEAD~
-
Git reset –hard HEAD~(checkout branchName) Note: Checkout is safe for the working directory. Action: After moving the HEAD, staging area, and workspace, you can use the method I demonstrated above to verify yourself.
Fourth, the end
At this point, Git retreat function explanation is basically finished, if you feel useful can point a thumb-up oh! I will continue to update, if there are any mistakes please point out, thank you for your audience master.
To get a PDF of the above content, go to GitHub and download it.
Address: Git study notes area