git tutorials to learn from Liao Xuefeng's official website
Undoing Changes
If the wrong line of code in the readme.txt years, such as
IS A Distributed Version Control Git System. Sound HAHAHA.
Git IS as Free Software at The Distributed an under the GPL.
I have come to test the modified
test management modified
test management to modify the second time
today, weather good, ah, really want a raise
The last line of code content is not natural, that in addition to manually delete the code error line, then there is a way to use git status to view the status of
$ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: readme.txt no changes added to commit (use "git add" and/or "git commit -a")
There is clearly a remark
(use "git restore <file>..." to discard changes in working directory)
You can use git restore + file name can be discarded modify the workspace
$ git restore readme.txt
Command git restore readme.txt
means that, put readme.txt
all the documents revoked modify the workspace, there are two cases:
The first is readme.txt
from the revised has not been placed in temporary storage area, and now, back and undo changes to the repository exactly the same state;
The second is readme.txt
after has been added to the staging area, has been modified and now returns to undo changes added to the state after the staging area.
In short, it is to make the file back to the last git commit
or the git add
state of.
Now, look at readme.txt
the contents of the file:
IS A Distributed Version Control Git System. Sound HAHAHA.
Git IS as Free Software at The Distributed an under the GPL.
I have come to test the modified
test management changes
Sure enough, the contents of the file recovery.
Another case is readme.txt
after has been added to the staging area prior to commit the need to withdraw, you can use git restore - staged its file name back into the work area
$ git status On branch master Changes to be committed: (use "git restore --staged <file>..." to unstage) modified: readme.txt
Then git status check, now staging area is clean workspace Edit:
$ git status On branch master Changes not staged for commit: (use "git add <file>..." to update what will be committed) (use "git restore <file>..." to discard changes in working directory) modified: readme.txt no changes added to commit (use "git add" and/or "git commit -a")
Remember how it discarded modify the workspace?
$ git restore readme.txt
$ git status
On branch master
nothing to commit, working tree clean
The whole world finally quiet!
Summary time.
Scenario 1: When you change the contents of a file chaotic workspace want direct discard modify the workspace with the command git restore file
.
Scenario 2: When you change not only upset the contents of a file workspace, also added to the staging area, to discard the changes in two steps, the first step command git restore -- staged 文件名
, returned to the scene 1, the second step by scene 1 operation.
Scenario 3: You have submitted improper modifications to the repository, you want to withdraw this submission, reference version rollback one, but the premise is not pushed to the remote repository.