git add vs git add all

时间:2014-05-03 15:26:43

标签: git github terminal add

git add .git add --all .之间有什么区别我阅读了手册,但我仍然没有理解。请在答案中包含.gitignore文件的影响方式:即--all假装没有忽略文件吗?

1 个答案:

答案 0 :(得分:0)

--all的替代名称,我认为更清晰,是--no-ignore-removal。从该替代名称可以立即看出它的作用:如果在工作树中删除了任何文件,它也会在索引中被删除。

创建了一个新的仓库,并添加了一个文件而没有提交,这是状态:

$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached ..." to unstage)

        new file:   file

现在,这是删除文件时发生的情况,git add在没有--all的情况下运行:

$ git add .
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal',
whose behaviour will change in Git 2.0 with respect to paths you removed.
Paths like 'file' that are
removed from your working tree are ignored with this version of Git.

* 'git add --ignore-removal ', which is the current default,
  ignores paths you removed from your working tree.

* 'git add --all ' will let you also record the removals.

Run 'git status' to check the paths you removed from your working tree.

$ git status
On branch master

Initial commit

Changes to be committed:
  (use "git rm --cached ..." to unstage)

        new file:   file

Changes not staged for commit:
  (use "git add/rm ..." to update what will be committed)
  (use "git checkout -- ..." to discard changes in working directory)

        deleted:    file

事实上,git add -A也会将其从索引中删除:

$ git add -A .
$ git status
On branch master

Initial commit

nothing to commit (create/copy files and use "git add" to track)

你在问题​​中提到gitignore,但--all与此无关。添加被忽略文件的选项是--force-f)。