Undo operation
In the course of recent use git, sometimes I encountered such a problem: habitual "add -A", which will be all the modifications are added to the staging area, but had to modify two files do not want to add Yeah, how to do this? git provides methods to undo operations. such as:
Cancel the changes have been temporarily stored
As I said earlier, the habit of "add -A" temporarily do not want to add the changes added to the staging area. The changes have been canceled staging of the method, git has been in every time you usegit status View the file when the state gives a solution,
➜ hexo-theme git:(master) ✗ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: processing/README.md
modified: processing/layout/_partial/navigation.jade
modified: processing/layout/_widget/archive.jade
modified: processing/layout/_widget/categories.jade
modified: processing/source/css/_base/base.scss
modified: processing/source/css/_base/variables.scss
modified: processing/source/css/_partial/navigation.scss
modified: processing/source/css/style.scss
You can use git reset HEAD ... a way to cancel the staging.
➜ hexo-theme git:(master) ✗ git reset HEAD *
Unstaged changes after reset:
M processing/README.md
M processing/layout/_partial/navigation.jade
M processing/layout/_widget/archive.jade
M processing/layout/_widget/categories.jade
M processing/source/css/_base/base.scss
M processing/source/css/_base/variables.scss
M processing/source/css/_partial/navigation.scss
M processing/source/css/style.scss
Next time you usegit status View file status can be seen
➜ hexo-theme git:(master) ✗ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
(use "git push" to publish your local commits)
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: processing/README.md
modified: processing/layout/_partial/navigation.jade
modified: processing/layout/_widget/archive.jade
modified: processing/layout/_widget/categories.jade
modified: processing/source/css/_base/base.scss
modified: processing/source/css/_base/variables.scss
modified: processing/source/css/_partial/navigation.scss
modified: processing/source/css/style.scss
no changes added to commit (use "git add" and/or "git commit -a")
It can be seen now all the changes have not been temporarily stored.
Cancel changes to the document
Once when I was repairing a bug, modify a local file repository, is not yet complete, companion told me he had made the desired changes, and has been submitted to the remote. I stopped the work at hand, ready to pull, this time realized that if direct pull, merge, when bound to conflict, because my colleagues and I almost simultaneously modify the same file in the same place. But I have modified the file in many places, blindly CTRL + Z is difficult to solve the problem, this time I need to return my modified file to the state before the modification. Chances are very good at executiongit status When, also it gives a specific withdrawal method.
➜ hexo-theme git:(master) git status
On branch master
Your branch is up-to-date with 'origin/master'.
Changes not staged for commit:
(use "git add <file>..." to update what will be committed)
(use "git checkout -- <file>..." to discard changes in working directory)
modified: processing/layout/_widget/archive.jade
modified: processing/layout/_widget/categories.jade
modified: processing/layout/_widget/tags.jade
modified: processing/layout/layout.jade
modified: processing/source/css/_base/base.scss
no changes added to commit (use "git add" and/or "git commit -a")
Usegit checkout -- <filename> To cancel the change in the working directory.
➜ hexo-theme git:(master) ✗ git checkout -- *
➜ hexo-theme git:(master) git status
On branch master
Your branch is up-to-date with 'origin/master'.
nothing to commit, working directory clean
The effect is obvious! ! This command some danger, all changes to files are gone. If one is not careful modification will discard their needs, and it can only cry ......
Last revised submission
Sometimes when submitting found himself missing or multi-select several files, or by submitting information was wrong, just want to undo a commit, you can use--amend This option, resubmit
➜ hexo-theme git:(master) ✗ git add -A
➜ hexo-theme git:(master) ✗ git commit -m "commit wrong"
[master ebcbab2] commit wrong
4 files changed, 78 insertions(+), 106 deletions(-)
rewrite processing/source/css/_base/base.scss (64%)
Found himself submitted a "commit wrong" error message submission, do not be too nervous, enter the command
git commit --amend
After that, it will jump to the command line in vim, prompting you to modify the submitted information. Unless pushed to the remote end, everything that ~