撤销提交(完全提交和暂存区)
创建一个文件hello.txt
$ git status -s
A firstweb/src/a/b/c/hello.txt
修改一个文件TestTwo.java
$ git status -s
A firstweb/src/a/b/c/hello.txt
M firstweb/src/git/git7/TestTwo.java
提交TestTwo.java
$ git add TestTwo.java
fatal: pathspec 'TestTwo.java' did not match any files
查看暂存区
$ git status -s
A firstweb/src/a/b/c/hello.txt
M firstweb/src/git/git7/TestTwo.java
此处如果撤销commit提交需要执行(撤销提交)
git reset --soft HEAD^
撤销新添加的文件hello.text
$ git reset HEAD firstweb/src/a/b/c
再次查看暂存区(此时新添加文件状态改变了)
$ git status -s
M firstweb/src/git/git7/TestTwo.java
?? firstweb/src/a/
此时撤销TestTwo.java。还是使用重置命令。
$ git reset
Unstaged changes after reset:
M firstweb/src/git/git7/TestTwo.java
清除TestTwo.java中的改动(此时TestTwo.java文件回到修改前状态)
$ git checkout -- firstweb/src/git/git7/TestTwo.java
查看当前工作区修改内
$ git status
On branch master
Your branch is ahead of 'origin/master' by 7 commits.
(use "git push" to publish your local commits)
Untracked files:
(use "git add <file>..." to include in what will be committed)
firstweb/src/a/
nothing added to commit but untracked files present (use "git add" to track)
查看需要删除的文件夹内容(git clean)
$ git clean -nd
Would remove firstweb/src/a/
删除文件夹
$ git clean -fd
Removing firstweb/src/a/
查看当前状态
$ git status
On branch master
Your branch is ahead of 'origin/master' by 7 commits.
(use "git push" to publish your local commits)
nothing to commit, working tree clean
清除成功