git restore 和 git restore --staged的区别


git restore --staged 将文件从暂存区撤回工作区
git restore 将在工作区的文件撤销更改

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$  echo "Hello Git" >> hello.txt 

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   hello.txt

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

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$ git add hello.txt 
warning: LF will be replaced by CRLF in hello.txt.
The file will have its original line endings in your working directory

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$ git status
On branch master
Changes to be committed:
  (use "git restore --staged <file>..." to unstage)
        modified:   hello.txt

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$ git restore --staged hello.txt

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$ git status
On branch master
Changes not staged for commit:
  (use "git add <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
        modified:   hello.txt

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

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$ git restore hello.txt

sps-5130@sps-5130 MINGW64 /d/code/gitrep (master)
$ git status
On branch master
nothing to commit, working tree clean


免责声明!

本站转载的文章为个人学习借鉴使用,本站对版权不负任何法律责任。如果侵犯了您的隐私权益,请联系本站邮箱yoyou2525@163.com删除。



 
粤ICP备18138465号  © 2018-2025 CODEPRJ.COM