简体   繁体   English

"“git add *”和“git add -f *”之间的区别?"

[英]difference between "git add * " and "git add -f *"?

When I used git add *<\/code> it's skipping some files and folders.当我使用git add *<\/code>时,它会跳过一些文件和文件夹。 But the same command git add *<\/code> is working perfectly for some other project.但是相同的命令git add *<\/code>对其他一些项目非常有效。 But when I'm using git add -f *<\/code> is working fine.但是当我使用git add -f *<\/code>时工作正常。

"

git add man page : git add man page

The git add command will not add ignored files by default. 默认情况下,git add命令不会添加被忽略的文件。 If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files. 如果在命令行中显式指定了任何被忽略的文件,git add将失败并显示一个被忽略的文件列表。 Ignored files reached by directory recursion or filename globbing performed by Git (quote your globs before the shell) will be silently ignored. 由Git执行的目录递归或文件名通配所达到的忽略文件(在shell之前引用你的globs)将被默默忽略。 The git add command can be used to add ignored files with the -f (force) option. git add命令可用于使用-f(强制)选项添加被忽略的文件。

Okay, this is from the Git Reference Manual ref https://git-scm.com/docs/git-add : 好的,这是来自Git参考手册参考https://git-scm.com/docs/git-add

"The ' git add ' command will not add ignored files by default. If any ignored files were explicitly specified on the command line, git add will fail with a list of ignored files." “默认情况下,' git add '命令不会添加被忽略的文件。如果在命令行中显式指定了任何被忽略的文件,git add将失败并显示被忽略的文件列表。” "The git add command can be used to add ignored files with the -f (force) option." “git add命令可用于使用-f (强制)选项添加被忽略的文件。”

In git add * the * is interpreted by the shell, and has nothing to do with Git. git add **由shell解释,与Git无关。 If your shell is Bash, files and directories starting with . 如果你的shell是Bash,文件和目录以. will not be matched by * (by default), so they will not be passed to git add , and will not get added to the index. 不会与*匹配(默认情况下),因此它们不会被传递给git add ,也不会被添加到索引中。

Instead of git add * , if you want to add all files in the current directory, including the ones starting with . 如果要添加当前目录中的所有文件,包括以.开头的文件,而不是git add * . , it's better to use git add . ,最好使用git add . .

Also, as other answers pointed out, git add will not add files that are marked to be ignored. 此外,正如其他答案所指出的, git add不会添加标记为要忽略的文件。 You can force adding such files using -f , but most probably you don't want to do that, there are very few legitimate use cases of this flag. 您可以使用-f强制添加此类文件,但很可能您不希望这样做,此标志的合法用例非常少。

A very valuable comment by @torek: @torek的一个非常有价值的评论:

Worth noting: if git add * is being run in a Windows non-bash interpreter, the * is passed literally to git add , at which point Git, not the shell, interprets the * . 值得注意的是:如果git add *正在Windows非bash解释器中运行, *会直接传递给git add ,此时Git而不是shell会解释* In this case files and directories whose names start with . 在这种情况下,名称以...开头的文件和目录. will get added. 被添加。 One can simulate this on a Linux or similar system by running git add '*' , though there is no reason to bother (other than demonstration) since git add . 可以通过运行git add '*'在Linux或类似系统上模拟这个,但是自git add .以来没有理由去打扰(除了演示) git add . is just as effective. 同样有效。

The attribute "-f" or "--force" coming after "git add" command means that you are forcing the adding to the stagging area ignored files ( which mean that these files are going to be a part of the next commit) “git add”命令之后的属性“-f”或“--force”意味着您正在强制添加到暂存区域被忽略的文件(这意味着这些文件将成为下一次提交的一部分)

So the difference between "git add * " and "git add -f " means that in the first case you add all the files ( ) excepted the ignored files, and in the second case you add all the files (and you force git to add the ignored files which are notified in the .gitignore file)所以“git add *”和“git add -f ”之间的区别意味着在第一种情况下你添加了所有文件( )除了被忽略的文件,在第二种情况下你添加了所有文件(并且你强制git添加在 .gitignore 文件中通知的被忽略文件)

source : https://git-scm.com/docs/git-add#git-add--f来源: https ://git-scm.com/docs/git-add#git-add--f

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM