如果可用,git将使用此值。如果是 dt_dir ,git将知道 dir 是一个目录,并且不需要在确定/dir/实体是否匹配的路径。如果是 dt_unknown ,git将不知道哪种实体 dir 表示, will 需要调用 lstat 。但是,对于/dir 锚定的Gitignore条目,Git Care 哪种实体 dir 表示,因此绝对不需要呼叫 lstat 。但是,也许它不需要调用 lstat ,这样一无所获。
(应该/dir 名称a file ,并且您希望git存储该文件,或者在适当的情况下以无跟踪的方式投诉,您应该使用/dir /在这里,不必担心单个 lstat 系统调用的成本,即使它可以以数百微秒或低数量的毫秒而不是纳米秒为单位的微秒,甚至是毫秒 do 当然最终会加起来。)
As you note indirectly, these aren't semantically equivalent since they act differently if /dir is a file. However, if you somehow "know" that /dir will in fact be a directory, /dir and /dir/ would be the "efficient" ways to list these as they will omit opening-and-reading the directory.
Whether /dir/ is less efficient or just as efficient as /dir depends on your OS and its readdir implementation: when Git reads the directory / (the top of the working tree), it gets the name components ., .., README.txt (assuming there is such a file), abc (maybe a file, maybe a directory, we'll just assume there is something named abc), dir (a directory), and whatever else. It may also get a useful d_type field: POSIX only requires a d_name and d_ino, but Linux and the BSDs have a d_type field. The OS will fill in d_type with one of:
Git will use this value, if it's available. If it isDT_DIR, Git will know that dir is a directory and won't need to call lstat on the path when deciding whether the /dir/ entity matches. If it is DT_UNKNOWN, Git won't know what kind of entity dir represents and will need to call lstat. However, for the /dir anchored gitignore entry, Git doesn't care what kind of entity dir represents, so it definitely won't need to call lstat. But maybe it doesn't need to call lstat anyway, so that this gains nothing.
(Should /dir name a file and you want Git to store that file if it exists, or complain about it as untracked as appropriate, you should use /dir/ here and not worry about the cost of a single lstat system call, even though it may be measured in hundreds of microseconds, or even low-digit milliseconds, rather than nanoseconds. But milliseconds do add up eventually, of course.)
/folderName => ignore folderName || fileName from root directory
/folderName/ => ignore folderName from root directory
But if you folderName/ ignore all folders with the name folderName. I would guess that that tokes more time because he iterate recursive over all folders from root upwards.
but in my opinion it doesn't matter. gitignore is not important for the programme and has no influence on the performance of the programm.
发布评论
评论(2)
正如您间接注意的那样,这些在语义上并不等同,因为如果
/dir
是 file ,它们的作用有所不同。但是,如果您以某种方式“知道”/dir
实际上 be 目录,/dir
和/dir/将是列出这些列表的“有效”方法,因为它们将省略打开和阅读目录。
/dir/
是是否有效或/dir
取决于您的OS及其readdir
实现:当git读取目录/
(工作树的顶部)时,它获取名称组件。
。,.. < /code>,
),readme.txt
(假设有这样的文件),abc
(也许是文件,也许是目录,我们只是假设有一些名为<的东西代码> ABCdir
(目录)等。 May 还获得有用的d_type
字段: POSIX仅需要d_name
和d_ino
,但是Linux和BSD具有d_type
字段。操作系统将填充d_type
,其中一个:dt_unknown
:我们没有告诉您任何东西dt_dir
:此实体用于目录dt_reg
:此实体适用于一个常规文件,如果可用,git将使用此值。如果是
dt_dir
,git将知道dir
是一个目录,并且不需要在确定/dir/
实体是否匹配的路径。如果是dt_unknown
,git将不知道哪种实体dir
表示, will 需要调用lstat
。但是,对于/dir
锚定的Gitignore条目,Git Care 哪种实体dir
表示,因此绝对不需要呼叫lstat
。但是,也许它不需要调用lstat
,这样一无所获。(应该
/dir
名称a file ,并且您希望git存储该文件,或者在适当的情况下以无跟踪的方式投诉,您应该使用/dir /
在这里,不必担心单个lstat
系统调用的成本,即使它可以以数百微秒或低数量的毫秒而不是纳米秒为单位的微秒,甚至是毫秒 do 当然最终会加起来。)As you note indirectly, these aren't semantically equivalent since they act differently if
/dir
is a file. However, if you somehow "know" that/dir
will in fact be a directory,/dir
and/dir/
would be the "efficient" ways to list these as they will omit opening-and-reading the directory.Whether
/dir/
is less efficient or just as efficient as/dir
depends on your OS and itsreaddir
implementation: when Git reads the directory/
(the top of the working tree), it gets the name components.
,..
,README.txt
(assuming there is such a file),abc
(maybe a file, maybe a directory, we'll just assume there is something namedabc
),dir
(a directory), and whatever else. It may also get a usefuld_type
field: POSIX only requires ad_name
andd_ino
, but Linux and the BSDs have ad_type
field. The OS will fill ind_type
with one of:DT_UNKNOWN
: we didn't tell you anythingDT_DIR
: this entity is for a directoryDT_REG
: this entity is for a regular fileGit will use this value, if it's available. If it is
DT_DIR
, Git will know thatdir
is a directory and won't need to calllstat
on the path when deciding whether the/dir/
entity matches. If it isDT_UNKNOWN
, Git won't know what kind of entitydir
represents and will need to calllstat
. However, for the/dir
anchored gitignore entry, Git doesn't care what kind of entitydir
represents, so it definitely won't need to calllstat
. But maybe it doesn't need to calllstat
anyway, so that this gains nothing.(Should
/dir
name a file and you want Git to store that file if it exists, or complain about it as untracked as appropriate, you should use/dir/
here and not worry about the cost of a singlelstat
system call, even though it may be measured in hundreds of microseconds, or even low-digit milliseconds, rather than nanoseconds. But milliseconds do add up eventually, of course.)如果您想忽略文件夹,请使用:
/folderName
=>忽略文件夹名称 ||根目录中的文件名/folderName/
=>忽略根目录中的folderName但是如果您
folderName/
忽略所有名为folderName 的文件夹。我猜这会花费更多时间,因为他从根目录向上递归遍历所有文件夹。但在我看来这并不重要。 gitignore 对于程序来说并不重要,对程序的性能没有影响。
If you want ignore a folder use:
/folderName
=> ignore folderName || fileName from root directory/folderName/
=> ignore folderName from root directoryBut if you
folderName/
ignore all folders with the name folderName. I would guess that that tokes more time because he iterate recursive over all folders from root upwards.but in my opinion it doesn't matter. gitignore is not important for the programme and has no influence on the performance of the programm.