git rm與直接rm的區別


git rm

行為:

  1.刪除一個文件

  2.將被刪除的這個文件納入緩存區

$ git rm a
rm 'a'
$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    a

提交:

  直接 git commit -m ''

$ git commit -m 'delete a'
[master 1cd6efe] delete a
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 a

$ git status
On branch master
nothing to commit, working directory clean

恢復:

  1. 恢復暫存區

  2. 恢復工作區

$ git reset HEAD a
Unstaged changes after reset:
D       a

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    a

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

$ git checkout -- a
$ git status
On branch master
nothing to commit, working directory clean

 

直接調用系統的rm

行為:

  從工作區刪除了一個文件

$ rm a

$ git status
On branch master
Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

        deleted:    a

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

提交:

  1.把修改加入暫存區

  2.提交暫存區的改動

$ git add a

$ git status
On branch master
Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

        deleted:    a

$ git commit -m 'delete a '
[master 689a73d] delete a
 1 file changed, 0 insertions(+), 0 deletions(-)
 delete mode 100644 a

$ git status
On branch master
nothing to commit, working directory clean

恢復:

  直接恢復工作區就好了,git checout -- file

$ git checkout -- a

$ git status
On branch master
nothing to commit, working directory clean

 

 

 

  

 


免責聲明!

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



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