2011-12-12 89 views
43

當我做了git commit -a,我看到以下內容:Git commit -a「未跟蹤文件」?

# Please enter the commit message for your changes. Lines starting 
    # with '#' will be ignored, and an empty message aborts the commit. 
    # On branch better_tag_show 
    # Changes to be committed: 
    # (use "git reset HEAD <file>..." to unstage) 
    # 
    # modified: ../assets/stylesheets/application.css 
    # modified: ../views/pages/home.html.erb 
    # modified: ../views/tags/show.html.erb 
    # modified: ../../db/seeds.rb 
    # 
    # Untracked files: 
    # (use "git add <file>..." to include in what will be committed) 
    # 
    # ../assets/stylesheets/ 
    # ../views/pages/ 

什麼是那些未跟蹤的文件是什麼意思?所有的變化都被確認了。我不明白爲什麼git在這裏警告我關於未跟蹤的文件。

編輯

好,我看到了很多困惑的答覆。這是我在git commit -a之後發生的事情。

# On branch master 
nothing to commit (working directory clean) 

正如您所看到的,除了那些應用了更改的這四個文件以外沒有其他任何東西。

我的問題應該改寫如下:爲什麼git會在跟蹤此提交中的所有更改時警告我關於未跟蹤的文件?

換句話說,是在GIT中的未跟蹤警告提交消息不必要

+1

'(使用 「混帳添加 ...」 中包括哪些將被提交)' – zengr

+0

zengr不需要,因爲git commit -a會將所有更改提交到已跟蹤的文件。 – disappearedng

+3

直到現在,文件從來沒有被「添加」過,它是必需的。從'-a'的文檔:*告訴命令自動對已被修改和刪除的文件進行分段處理,但是**沒有告訴git的新文件不受影響**。 –

回答

24

git commit -am "msg"不一樣git add filegit commit -m "msg"

如果這是從來沒有加入到Git的跟蹤,你仍然需要做git add file

The 「git commit -a」 command is a shortcut to a two-step process. After you modify a file that is already known by the repo, you still have to tell the repo, 「Hey! I want to add this to the staged files and eventually commit it to you.」 That is done by issuing the 「git add」 command. 「git commit -a」 is staging the file and committing it in one step.

來源的一些文件:"git commit -a" and "git add"

1

由於名字暗示'未跟蹤文件'是沒有被git跟蹤的文件。他們不在您的臨時區域,並且不屬於任何以前的提交。如果你想要它們被版本化(或者被git管理),你可以通過使用'git add'來告訴'git'。檢查本章Recording Changes to the Repository在使用一個很好的視覺,以提供有關記錄更改混帳回購協議,並解釋術語「跟蹤」和「未跟蹤」

40

對於有同樣的問題別人,嘗試運行

一個很好的解釋了 Progit

git add . 這將增加當前目錄下的所有文件來跟蹤(包括未跟蹤),然後使用

git commit -a提交所有跟蹤文件。

至於建議由@Pacerier,一個內襯做同樣的事情是

git add -A

+1

'git commit -a'將提交所有跟蹤的文件,而不跟蹤未跟蹤的文件。 'git add .'將跟蹤當前目錄中的未跟蹤文件。 git add -a會跟蹤所有未跟蹤的文件。 – here

+1

@coding_idiot,爲什麼不使用'git add -A'? – Pacerier

+0

@Pacerier謝謝,更新了答案。 –

2

你應該輸入到命令行

git add --all 

這將提交所有未跟蹤文件

1
  1. 首先你需要添加所有未跟蹤的文件。使用此命令行 git的添加*

  2. 然後提交使用此命令行 git的承諾-a