1. 程式人生 > >Git常用操作之刪除操作

Git常用操作之刪除操作

delete stat chan update 常用 del 進入 code res

Git刪除操作有兩種

1.git rm

2.rm

有何不同?

git rm直接包含了add操作。show you the code

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git rm 2.txt
rm ‘2.txt‘

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git status
# On branch dev
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       deleted:    2.txt
#

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git reset HEAD 2.txt
Unstaged changes after reset:
D       2.txt

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git status
# On branch dev
# 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:    2.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git checkout 2.txt

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git status
# On branch dev
nothing to commit, working directory clean

  可以從上面的代碼看出,當你執行了git rm操作後,已經是進入到暫存區的。

讓我們看看rm操作的結果。

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ rm 2.txt

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git status
# On branch dev
# 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:    2.txt
#
no changes added to commit (use "git add" and/or "git commit -a")

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git checkout 2.txt

bocur@DESKTOP-PTRIQEA /d/project/study (dev)
$ git status
# On branch dev
nothing to commit, working directory clean

  從上面可以看到,執行了rm操作後,是沒有添加到暫存區的。依然是需要手動的去add。

Git常用操作之刪除操作