2011-12-12 90 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