2014-02-12 32 views
0

我已經做了以下(爲了學習git rm)。爲新文件運行'git rm'?

在空文件夾中創建一個空的存儲庫。 創建一個名爲test.txt的文件,對其進行修改,然後運行以下命令(以及相應的結果)。

git rm test.txt -> `fatal: pathspec 'test.txt' did not match any files` 

git add test.txt && git rm test.txt -> 
error: 'test.txt' has changes staged in the index 
        (use --cached to keep the file, or -f to force removal) 

所以,我的問題是:

當將git rm test.txt的是真正有用的?

回答

1

When would git rm test.txt be actually useful?

當你已經添加文件提交到存儲庫。 The docs tell usgit rm用於:

Remove files from the index, or from the working tree and the index.

+0

哦,所以當文件只是在臨時區域是沒有用的...... –

+0

什麼工作樹和索引之間的區別?我一直聽到工作目錄,暫存區和git目錄(存儲庫)。 –

+0

大多數時候,如果你還沒有提交這個文件,並且你想「撤銷」一個'git add',那麼你只需要使用'git reset'。但有一個例外:['git rm --cached'是撤銷'git add'的唯一方法,如果你的版本庫沒有提交的話。](http://stackoverflow.com/a/682343/139010) –