2011-12-01 78 views
0

當我修改一個文件,然後運行git status我得到:奇怪的行爲與git的狀態

# On branch master 
# Changes not staged for commit: 
# (use "git add <file>..." to update what will be committed) 
# (use "git checkout -- <file>..." to discard changes in working directory) 
# 
# modified: app/models/category.rb 
# 
no changes added to commit (use "git add" and/or "git commit -a") 

爲什麼有行(use "git add <file>..." to update what will be committed)? 我的回購中沒有要添加的文件。

+1

您可能還會喜歡http://stackoverflow.com/questions/1844161/git-status-a-bit-confusing。這個問題,也是關於'git status',與你的問題有點不同,但你可能會覺得它很有趣。 –

回答

1

您還可以使用git add來對已修改的文件進行提交階段。

0

正如其他人提到的,這是因爲git增加了另一個階段,比如顛覆。 git存儲庫的分支包含文件的提交版本,git索引保存將會提交的更改,並且文件系統保存實際當前的文件狀態。

即使文件已被跟蹤,但當文件被修改時,除非您將其標記爲「是,請執行此操作」,否則不會顯式提交。有幾個方法可以做到這一點:

git add someFile;git commit; #explicitly add and then commit marked files 
git commit someFile -m " Change to someFile."; #explicitly commit a list of files 
git commit -am " Latest set of changes to all tracked files"; #shotgun approach, commits all changes to all tracked files or added files 

我建議使用

git commit someFile anotherFile aWholeOtherFile -m " Commit message." 

明確,直到你真的在混帳犯了一個手柄,可以更清楚如何處理應對意外承諾你並不是故意的,然後轉向更簡單的方法git commit -am " Commit message."