为什么 "git add *" 排除 .gitignore?
Why does "git add *" excludes .gitignore?
我有 .git忽略文件,其中包含已排除文件的名称。当我删除 .git 文件夹并在 git add *
之后执行 git init
时,我希望添加所有未被 .gitignore 忽略的文件。但是,.gitignore 在 git status
中显示为未跟踪文件,即使我在 .gitignore 中包含 !.gitignore
,我也必须使用 git add .gitignore
手动添加它。
因为您的命令中的 *
实际上被替换为当前目录 除了 那些盯着 .
的文件(和目录)的名称。如果你还想包括 .gitignore 你应该调用:
git add * .gitignore
如果您想包含所有点文件,请调用:
git add * .[!.]*
如果您正在使用 zsh,您可以使用更简单的模式:
git add * .*
我有 .git忽略文件,其中包含已排除文件的名称。当我删除 .git 文件夹并在 git add *
之后执行 git init
时,我希望添加所有未被 .gitignore 忽略的文件。但是,.gitignore 在 git status
中显示为未跟踪文件,即使我在 .gitignore 中包含 !.gitignore
,我也必须使用 git add .gitignore
手动添加它。
因为您的命令中的 *
实际上被替换为当前目录 除了 那些盯着 .
的文件(和目录)的名称。如果你还想包括 .gitignore 你应该调用:
git add * .gitignore
如果您想包含所有点文件,请调用:
git add * .[!.]*
如果您正在使用 zsh,您可以使用更简单的模式:
git add * .*