2017-08-13 92 views
1

通常變化時,我有犯我的日常工作中我使用:Git的,提交和推送與刪除的文件無法正常工作

git add * 
git commit -m "my commit message" 
git push origin master 

這個命令是非常基礎。但我注意到,刪除的文件不會從我的遠程倉庫中刪除。事實上,如果我在Github上推送更改後刪除了一個通用文件「example.txt」(在本地文件夾中),該文件仍然保留。

git add *通知應該識別刪除的文件,還是不能? 如何從遠程倉庫中刪除已刪除的文件?

感謝

+0

你有一個答案在下面,但我會建議你只使用'git status',然後複製/粘貼你想要提交的文件。這會迫使你回顧一下你實際正在做的事情,而不是用'git add'覆蓋。' –

+0

看看這個鏈接,以深入理解git add arguments:https://stackoverflow.com/questions/572549/difference-between -git-add-a-and-git-add – Samuel

回答

0

git add不會默認記錄文件刪除。通過--all標誌會告訴它也查找刪除的文件。

蒂姆Biegeleisen建議,值得結合使用的git status看到你的工作目錄的更改,然後使用git add <filename>一個將它們添加一個。通過這種方式,您可以更清楚地瞭解並控制添加到暫存區域的內容。你也可以使用git add <directory>來一次添加一個完整的目錄,或者git add -i,它會要求git引導你完成每個文件的更改,並讓你選擇暫存或忽略它。

1

git add *不跟蹤它只包括修改刪除的文件或添加新的文件。你必須使用

$ git add . --all 

跟蹤的所有文件(包括刪除的文件)

參考文獻:docs

+0

我已經嘗試過,但仍然無法正常工作。 –

+0

嘗試'git status'並檢查跟蹤的文件。上面提到的方法是文檔中提到的非常標準。 –

+0

使用'git status'我看過: Sul分支主人 你的分支是'origin/master'的最新版本。 沒有提交,工作樹清理 –

1

不完全是,從這個web

使用git rm

git rm [-f | --force] [-n] [-r] [--cached] [--ignore-unmatch] [--quiet] [--] <file>…​ 

Description: 

Remove files from the index, or from the working tree and the index. git 
rm will not remove a file from just your working directory. (There is no 
option to remove a file only from the working tree and yet keep it in the 
index; use /bin/rm if you want to do that.) The files being removed have 
to be identical to the tip of the branch, and no updates to their 
contents can be staged in the index, though that default behavior can be 
overridden with the -f option. When --cached is given, the staged content 
has to match either the tip of the branch or the file on disk, allowing 
the file to be removed from just the index. 
+0

這是正確的答案。然而,我感覺@aso可能期望在該庫中沒有該文件的NO TRACE。它將留在'歷史'中。 'git rm'然後提交只是改變該提交的* state *(指向歷史記錄)。 –

+0

@ThomParkin您可能想要查看git文檔,您將看到rm和add --all都適用於刪除文件和更新到遠程回購站。 [this](https://stackoverflow.com/questions/572549/difference-between-git-add-a-and-git-add)也會有幫助 –

+1

@ThomParkin你幾乎擁有它 - 'git rm' doesn'當文件被添加時,t改變提交的狀態。它將索引/緩存/暫存區域中的文件刪除記錄下來。然後,當你運行'git commit'時,新的提交從存儲庫中刪除該文件。然而,你對它仍然在歷史中有一個好的觀點 - 例如,你不會只想把包含密碼的文件「git rm」,因爲任何人都可以通過查看(例如)在運行'git rm; git commit'。 – instantepiphany