我上傳了一堆文件,但在提交到資源庫之前刪除了它們。當我做一個git status
我看到這一點:如何清除狀態條目
# deleted: filename.fileext
我已經能夠提交新的變化,但這些刪除的文件的狀態檢查仍然出現。有人能解釋爲什麼嗎?我如何擺脫它們?
我上傳了一堆文件,但在提交到資源庫之前刪除了它們。當我做一個git status
我看到這一點:如何清除狀態條目
# deleted: filename.fileext
我已經能夠提交新的變化,但這些刪除的文件的狀態檢查仍然出現。有人能解釋爲什麼嗎?我如何擺脫它們?
git add -u
git commit -m "Deleted files manually"
如果使用rm
命令來刪除文件,運行git rm <file_path_to_be_removed>
告訴這些文件被刪除飯桶。
rm
命令只能刪除物理文件。然後你需要通知git。
[email protected]:/tmp/git$ touch a.txt [email protected]:/tmp/git$ git add a.txt [email protected]:/tmp/git$ git commit -m"m" [master (root-commit) 03f6743] m 0 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 a.txt [email protected]:/tmp/git$ git status # On branch master nothing to commit (working directory clean) [email protected]:/tmp/git$ rm a.txt [email protected]:/tmp/git$ git status # On branch master # Changes not staged for commit: # (use "git add/rm ..." to update what will be committed) # (use "git checkout -- ..." to discard changes in working directory) # # deleted: a.txt # no changes added to commit (use "git add" and/or "git commit -a") [email protected]:/tmp/git$ git rm a.txt rm 'a.txt' [email protected]:/tmp/git$ git status # On branch master # Changes to be committed: # (use "git reset HEAD ..." to unstage) # # deleted: a.txt # [email protected]:/tmp/git$
絲束deleted
狀態是不同。第一個是更改沒有上演提交:,第二個是要提交的更改: 因此,只需運行git commimt -m"Message"
,然後一切都很乾淨。
我這樣做了,但是當我運行'git status'時,文件仍然顯示爲'deleted'。任何想法爲什麼發生這種情況? – dopatraman 2012-08-14 13:47:11
@codeninja結帳我的更新 – xiaowl 2012-08-14 13:54:49
不要忘記提交後! – kbdjockey 2012-08-14 13:54:52
'-u'命令的作用是什麼? – dopatraman 2012-08-14 13:46:01
請參閱git add help: 只匹配針對索引中的已經跟蹤的文件而不是工作樹。這意味着它永遠不會放置新文件,但它會逐步修改已跟蹤文件的新內容,並且如果工作樹中的相應文件已被刪除,它將從索引中刪除文件。 如果沒有給出,則默認爲「。」;換句話說,更新當前目錄及其子目錄中的所有跟蹤文件。 –
kbdjockey
2012-08-14 13:53:25