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。
原文:http://www.cnblogs.com/bocurry/p/7739291.html