4.6.1、git撤销工作区的修改:
Git checkout -- 文件名 就是将文件还原到原来和版本库中的相同
W@thinksite MINGW64 /d/thinksitegit (master)
$ git status
On branch 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: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
W@thinksite MINGW64 /d/thinksitegit (master)
$ git diff
diff --git a/hello.txt b/hello.txt
index 007c377..b81f15c 100644
--- a/hello.txt
+++ b/hello.txt
@@ -1,2 +1,3 @@
welcome to git
-this is modify hello.txt
\ No newline at end of file
+this is modify hello.txt
+fuck Boss
\ No newline at end of file
W@thinksite MINGW64 /d/thinksitegit (master)
$ git checkout -- hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ cat hello.txt
welcome to git
this is modify hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git status
On branch master
nothing to commit, working tree clean
4.6.1、撤销暂存区的修改:
Git reset HEAD 文件名 撤销暂存区到工作区
Git checkout -- 文件名 撤销工作区的修改
W@thinksite MINGW64 /d/thinksitegit (master)
$ git status
On branch 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: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
W@thinksite MINGW64 /d/thinksitegit (master)
$ git add hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git add hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git status
On branch master
Changes to be committed:
(use "git reset HEAD <file>..." to unstage)
modified: hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git reset HEAD hello.txt
Unstaged changes after reset:
M hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git status
On branch 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: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
W@thinksite MINGW64 /d/thinksitegit (master)
$ git checkout -- hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git status
On branch master
nothing to commit, working tree clean
4.6.1、撤销仓库中的修改: 直接仓库回退到上一个仓库快照
Git reset --hard 快照id/HEAD^/HEAD-1
W@thinksite MINGW64 /d/thinksitegit (master)
$ git status
On branch 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: hello.txt
no changes added to commit (use "git add" and/or "git commit -a")
W@thinksite MINGW64 /d/thinksitegit (master)
$ git add hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git commit -m "Fuck Boss modify"
[master aa9678a] Fuck Boss modify
1 file changed, 2 insertions(+), 1 deletion(-)
W@thinksite MINGW64 /d/thinksitegit (master)
$ git log --pretty=oneline
aa9678a51b904fb865188e873665f83ac26cea22 (HEAD -> master) Fuck Boss modify
d7d6c09359a4df4457962982a09ba713f4016211 delete hello1.txt
c18161641718a9f0c81c9b87aeea90949513b25b modify hello.txt
2afbe025603a89ce0e1e64c8f9e6475eeaad6bbf add more hello1.txt hello2.txt
a630654e622f39cb6175d3b4166f69baccaac977 add file hello.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ git reset --hard d7d6c09359a4df4457962982a09ba713f4016211
HEAD is now at d7d6c09 delete hello1.txt
W@thinksite MINGW64 /d/thinksitegit (master)
$ cat hello.txt
welcome to git
this is modify hello.txt