git命令--git checkout 之 撤销提交到暂存区的更改

SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (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:   ihr-producer/src/main/resources/spring/applicationContext-producer.xml

no changes added to commit (use "git add" and/or "git commit -a")

SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master)
$ git add .

SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master)
$ git status        【由于文件被添加到了暂存区,等待提交,所以显示为绿色】
On branch master
Your branch is up-to-date with 'origin/master'.

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        modified:   ihr-producer/src/main/resources/spring/applicationContext-producer.xml


SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master)
$ git reset HEAD .
Unstaged changes after reset:
M       ihr-producer/src/main/resources/spring/applicationContext-producer.xml

SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master)
$ git status          【由于使用"git reset HEAD ."又撤销了前面所做的所有的add操作,所以这里又恢复到红色】
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:   ihr-producer/src/main/resources/spring/applicationContext-producer.xml

no changes added to commit (use "git add" and/or "git commit -a")

SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master)
$ git checkout .        【撤销对工作区所做的一切更改,这样以前所有的修改就都没有,慎用!】

SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master)
$ git status
On branch master
Your branch is up-to-date with 'origin/master'.

nothing to commit, working directory clean

SYJ@WIN-95I6OG3AT1N /D/gitlab/ihr-kafka-produce (master)
$

如果觉得本文对您有帮助,不妨扫描下方微信二维码打赏点,您的鼓励是我前进最大的动力:

原文地址:https://www.cnblogs.com/jun1019/p/6656118.html