1. 程式人生 > >rm, git rm, git rm --cached 區別與關系

rm, git rm, git rm --cached 區別與關系

rect git git命令 cnblogs plain 直接 staging lai working

HEAD, staging area, working copy在上篇《Git命令之回退篇 git revert git reset》已經講過,不明白請自行傳送過去。

1. rm

  1. 是僅僅刪除working directory裏的文件,但若需要刪除staging area和HEAD上的文件,需要先執行git add, 然後執行git commit -m "delete xxx";

  2. 或者直接執行一句 git commit -am "delete xxx" ,多加一個"-a"參數,這個參數的功能之一就是將working directory裏刪除的文件從staging area中刪除.

2. git rm

  1. 相當於rm + git add, 即working directory和staging area中都刪除了該文件

  2. 若想推到本地repository只需git commit -m "delete xxx"即可

  3. 若想推到遠程repository只需git push

3. git rm --cached

  1. 保留本地文件,僅僅刪除staging area中的文件,停止跟蹤該文件的變化

  2. 在commit的之後repository裏也會刪除該文件,不再跟蹤

rm, git rm, git rm --cached 區別與關系