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