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)
$

 

如果覺得本文對您有幫助,不妨掃描下方微信二維碼打賞點,您的鼓勵是我前進最大的動力:

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM