2014-09-24 95 views
6

我有一個奇怪的問題,那就是未跟蹤文件。 我有一個跟蹤文件index.css。然後我將它添加到.gitignore。然後我運行下面的,並得到一個輸出:使用Git從跟蹤中刪除文件時遇到問題

$ git rm --cached build/development/css/index.css 
rm 'build/development/css/index.css' 

運行git status給出如下:

$ git status 
On branch master 
Your branch is up-to-date with 'origin/master'. 

Changes to be committed: 
    (use "git reset HEAD <file>..." to unstage) 

     deleted: build/development/css/index.css 

當試着提交變化,我得到以下錯誤:

Error:On branch master 
Your branch is up-to-date with 'origin/master'. 
nothing to commit, working directory clean 
during executing git commit --only -F C:\Users\dtv\AppData\Local\Temp\git-commit-msg-7154374096157077481.txt -- build/development/css/index.css 

如果我嘗試將更改提交到index.css以及其他更改,提交沒有錯誤。但是仍然檢測到文件的更改。我究竟做錯了什麼?

+0

我無法重現你的問題與Git版本1.9。你正在使用哪個版本? – 2014-09-24 13:26:11

+0

@Zeeker,1.9.4。這個文件有問題。我無法弄清楚什麼。我可以採取哪些步驟來追蹤它? – 2014-09-24 13:31:47

+0

並非如此,但可能是您資料庫中的某些內容被破壞了。您始終可以嘗試重新登錄存儲庫並重試。 – 2014-09-24 13:33:38

回答

1

問題是git commit--only選項。從git-commit手冊頁:

Make a commit only from the paths specified on the command line, disregarding any contents that have been staged so far.

它試圖提交這個文件,從之前不顧以前git rm --cached命令。

1
  • 根據我的觀察,如果我們使用這個git rm --cached filename命令它只會在那個時候忽略它。
  • 如果您在.gitignore中添加該文件,git會永久忽略(取消)該文件。將文件名或路徑的.gitignore後,我們必須執行以下命令untrack從下一次這些文件起

    首先提交任何未更改代碼,然後,運行以下命令

    git rm -r --cached . - >這從索引移除的任何改變的文件(暫存區)

    git add .

    git commit -m ".gitignore is now working" - >提交更改

1

你試過:

的git更新指數--assume未發生變化的文件路徑

這將標誌着指數和Git該文件將停止跟蹤該文件的任何修改。在與的.gitignore將這個文件組合將停止其顯示爲修改使用

當git的狀態

您還可以查看文檔的update-index