撤销提交(完全提交和暂存区)

撤销提交(完全提交和暂存区)

创建一个文件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

清除成功

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值