Git 命令显示 .gitignore 忽略了哪些特定文件

发布于 2024-07-12 09:53:24 字数 514 浏览 12 评论 0原文

我正在接触 Git,并遇到以下问题:

我的项目源树:

/
|
+--src/
+----refs/
+----...
|
+--vendor/
+----...

我的供应商分支中有代码(当前为 MEF),我将在那里进行编译,然后将引用移至 /src/refs 这是项目从中获取它们的地方。

我的问题是我将 .gitignore 设置为忽略 *.dll*.pdb。 我可以执行 git add -f bar.dll 来强制添加被忽略的文件,这是可以的,问题是我无法弄清楚列出哪些文件存在被忽略。

我想列出被忽略的文件,以确保我不会忘记添加它们。

我已阅读 git ls-files 上的手册页,但无法使其工作。 在我看来, git ls-files --exclude-standard -i 应该做我想做的事。 我缺少什么?

I am getting my feet wet with Git and have the following issue:

My project source tree:

/
|
+--src/
+----refs/
+----...
|
+--vendor/
+----...

I have code (currently MEF) in my vendor branch that I will compile there and then move the references into /src/refs which is where the project picks them up from.

My issue is that I have my .gitignore set to ignore *.dll and *.pdb. I can do a git add -f bar.dll to force the addition of the ignored file which is ok, the problem is I can not figure out to list what files exist that are ignored.

I want to list the ignored files to make sure that I don't forget to add them.

I have read the man page on git ls-files and can not make it work. It seems to me that git ls-files --exclude-standard -i should do what I want. What am I missing?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(12

辞别 2024-07-19 09:53:24

注:


也很有趣(在 qwertymk答案),您也可以使用 git check-ignore -v 命令,至少在 Unix 上(在 CMD Windows 会话中不起作用,但在 Windows CMD git bash 会话中起作用)

git check-ignore -- *
git check-ignore -v -- *

第二个显示.gitignore 的实际规则使文件在 git 存储库中被忽略。
在 Unix 上,使用“什么递归地扩展到当前目录中的所有文件?" 和 bash4+:

git check-ignore **/*

(或 find -exec 命令)

注意:https:// /stackoverflow.com/users/351947/Rafi B. 建议 在评论避免(有风险的)globstar

git check-ignore -v $(find . -type f -print)

确保从 .git 中排除文件/ 子文件夹。

CervEd注释,以避免 .git/

find . -not -path './.git/*' | git check-ignore --stdin

原始答案(2009)

git ls-files -i

应该有效,除了其源代码表示:

if (show_ignored && !exc_given) {
                fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
                        argv[0]);

exc_given?

事实证明,在 -i 之后还需要一个参数才能实际列出任何内容。

尝试:(

git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore

但这只会列出您的缓存(非忽略)对象,并带有过滤器,因此这并不完全是您想要的)


示例:

$ cat .git/ignore
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated HTML files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git ls-files --ignored \
    --exclude='Documentation/*.[0-9]' \
    --exclude-from=.git/ignore \
    --exclude-per-directory=.gitignore

实际上,在我的“gitignore”文件中(称为“排除'),我找到一个可以帮助您的命令行:

F:\prog\git\test\.git\info>type exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

所以......

git ls-files --ignored --exclude-from=.git/info/exclude
git ls-files -i --exclude-from=.git/info/exclude

git ls-files --others --ignored --exclude-standard
git ls-files -o -i --exclude-standard

应该可以解决问题。

(感谢honzajde指出在注释git ls-files -o -i --exclude -from...包含缓存文件:仅git ls-files -i --exclude-from...不包含< /em> -o) 确实如此。)

正如 ls-files 手册页--others 是重要部分,向您展示非缓存、非提交、通常被忽略的文件。

--exclude_standard 不仅仅是一个快捷方式,而且是一种包含所有标准“忽略模式”设置的方法。

排除标准
在每个目录中添加标准 git 排除:.git/info/exclude.gitignore,以及用户的全局排除文件


Git 2.44(2024 年第 1 季度),第 13 批,澄清了文档,其中 - -exclude-per-directory 选项被标记为已弃用,这让读者误以为将来可能有计划删除它,但这不是我们的意图。

请参阅 提交 0009542(2024 年 1 月 24 日),作者:Junio C Hamano (gitster)
(由 Junio C Hamano -- gitster -- 合并于 提交 bbc8c05,2024 年 2 月 2 日)

ls-files:避免动词“deprecate” “对于个别选项

e750951(“ls-files:指南人们使用 --exclude-standard 而不是其他 --exclude* 选项”,2023-01-13,Git v2.40.0-rc0 -- 合并批次#中列出13)更新了文档以提高 --exclude-standard 选项的可见性,它将 --exclude-per-directory 选项标记为“已弃用” ”。

虽然从技术上讲,被弃用并不一定意味着计划稍后将其删除,但它似乎会给读者带来困惑,尤其是当我们仅仅指的是

选项Y可以用来实现与选项相同的效果 
  X 更简单。   对于那些对两者都不熟悉的人 
  X或Y,我们建议在适当的时候使用Y。 
  

对于 --exclude-standard 与更细粒度的 --exclude-from--exclude-per-directory 的组合来说尤其如此< /code> 选项。
确实,仅通过给出前者就可以获得细粒度选项的一种常见组合,但这并不一定意味着不需要更细粒度的控制。

--exclude-per-directory的描述中说明我们推荐读者--exclude-standard的原因,而不是说该选项已被弃用。
另外,请详细说明模拟 --exclude-standard 的作用,以便用户可以对其进行细微的调整(例如“与 Git Porcelain 执行相同的操作,除非我不想阅读core.excludes 中的全局排除文件”)。

git ls-files 现在包含在其 手册页

中的目录及其子目录。 如果你是
尝试模仿 Porcelain 命令的工作方式,使用
--exclude-standard 选项反而更简单、更多
彻底。

git ls-files 现在包含在其 手册页

通常,当您
希望排除规则的应用方式与 Porcelain 相同
命令可以。 要模拟 --exclude-standard 指定的内容,您
可以给出--exclude-per-directory=.gitignore,然后指定:

  1. core.excludesfile配置指定的文件
    变量(如果存在)或 $XDG_CONFIG_HOME/git/ignore 文件。

  2. $GIT_DIR/info/exclude 文件。

通过 --exclude-from= 选项。

Notes:


Also interesting (mentioned in qwertymk's answer), you can also use the git check-ignore -v command, at least on Unix (doesn't work in a CMD Windows session, but works in a Windows CMD git bash session)

git check-ignore -- *
git check-ignore -v -- *

The second one displays the actual rule of the .gitignore which makes a file to be ignored in your git repo.
On Unix, using "What expands to all files in current directory recursively?" and a bash4+:

git check-ignore **/*

(or a find -exec command)

Note: https://stackoverflow.com/users/351947/Rafi B. suggests in the comments to avoid the (risky) globstar:

git check-ignore -v $(find . -type f -print)

Make sure to exclude the files from the .git/ subfolder though.

CervEd suggests in the comments, to avoid .git/:

find . -not -path './.git/*' | git check-ignore --stdin

Original answer (2009)

git ls-files -i

should work, except its source code indicates:

if (show_ignored && !exc_given) {
                fprintf(stderr, "%s: --ignored needs some exclude pattern\n",
                        argv[0]);

exc_given?

It turns out it needs one more parameter after the -i to actually list anything.

Try:

git ls-files -i --exclude-from=[Path_To_Your_Global].gitignore

(but that would only list your cached (non-ignored) object, with a filter, so that is not quite what you want)


Example:

$ cat .git/ignore
# ignore objects and archives, anywhere in the tree.
*.[oa]
$ cat Documentation/.gitignore
# ignore generated HTML files,
*.html
# except foo.html which is maintained by hand
!foo.html
$ git ls-files --ignored \
    --exclude='Documentation/*.[0-9]' \
    --exclude-from=.git/ignore \
    --exclude-per-directory=.gitignore

Actually, in my 'gitignore' file (called 'exclude'), I find a command line that could help you:

F:\prog\git\test\.git\info>type exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~

So....

git ls-files --ignored --exclude-from=.git/info/exclude
git ls-files -i --exclude-from=.git/info/exclude

git ls-files --others --ignored --exclude-standard
git ls-files -o -i --exclude-standard

Should do the trick.

(Thanks to honzajde pointing out in the comments that git ls-files -o -i --exclude-from... does not include cached files: only git ls-files -i --exclude-from... (without -o) does.)

As mentioned in the ls-files man page, --others is the important part, to show you non-cached, non-committed, normally ignored files.

--exclude_standard is not just a shortcut, but a way to include all standard "ignored patterns" settings.

exclude-standard
Add the standard git exclusions: .git/info/exclude, .gitignore in each directory, and the user's global exclusion file.


Git 2.44 (Q1 2024), batch 13, clarifies the documentation where the --exclude-per-directory option was marked as deprecated, which confused readers into thinking there may be a plan to remove it in the future, which was not our intention.

See commit 0009542 (24 Jan 2024) by Junio C Hamano (gitster).
(Merged by Junio C Hamano -- gitster -- in commit bbc8c05, 02 Feb 2024)

ls-files: avoid the verb "deprecate" for individual options

When e750951 ("ls-files: guide folks to --exclude-standard over other --exclude* options", 2023-01-13, Git v2.40.0-rc0 -- merge listed in batch #13) updated the documentation to give greater visibility to the --exclude-standard option, it marked the --exclude-per-directory option as "deprecated".

While it is technically correct that being deprecated does not necessarily mean it is planned to be removed later, it seems to cause confusion to readers, especially when we merely mean

The option Y can be used to achieve the same thing as the option
X much simpler. To those of you who aren't familiar with either
X or Y, we would recommend to use Y when appropriate.

This is especially true for --exclude-standard vs the combination of more granular --exclude-from and --exclude-per-directory options.
It is true that one common combination of the granular options can be obtained by just giving the former, but that does not necessarily mean a more granular control is not necessary.

State the reason why we recommend readers --exclude-standard in the description of --exclude-per-directory, instead of saying that the option is deprecated.
Also, spell out the recipe to emulate what --exclude-standard does, so that the users can give it minute tweaks (like "do the same as Git Porcelain, except I do not want to read the global exclusion file from core.excludes").

git ls-files now includes in its man page:

directory and its subdirectories in . If you are
trying to emulate the way Porcelain commands work, using
the --exclude-standard option instead is easier and more
thorough.

git ls-files now includes in its man page:

Generally, you should be able to use --exclude-standard when you
want the exclude rules applied the same way as what Porcelain
commands do. To emulate what --exclude-standard specifies, you
can give --exclude-per-directory=.gitignore, and then specify:

  1. The file specified by the core.excludesfile configuration
    variable, if exists, or the $XDG_CONFIG_HOME/git/ignore file.

  2. The $GIT_DIR/info/exclude file.

via the --exclude-from= option.

伴随着你 2024-07-19 09:53:24

有一个更简单的方法来做到这一点(git 1.7.6+):

git status --ignored

请参阅 有没有办法告诉 git-status 忽略.gitignore 文件的影响?

There is a much simpler way to do it (git 1.7.6+):

git status --ignored

See Is there a way to tell git-status to ignore the effects of .gitignore files?

累赘 2024-07-19 09:53:24

另一个非常干净的选项(没有双关语。):

git clean -ndX

说明:

$ git help clean

git-clean - Remove untracked files from the working tree
-n, --dry-run - Don't actually remove anything, just show what would be done.
-d - Remove untracked directories in addition to untracked files.
-X - Remove only files ignored by Git.

注意:此解决方案不会显示已被删除的忽略文件。

Another option that's pretty clean (No pun intended.):

git clean -ndX

Explanation:

$ git help clean

git-clean - Remove untracked files from the working tree
-n, --dry-run - Don't actually remove anything, just show what would be done.
-d - Remove untracked directories in addition to untracked files.
-X - Remove only files ignored by Git.

Note: This solution will not show ignored files that have already been removed.

恋竹姑娘 2024-07-19 09:53:24

虽然通常是正确的,但您的解决方案并不在所有情况下都有效。
假设 repo 目录像这样:

# ls **/*                                                                                                       
doc/index.html  README.txt  tmp/dir0/file0  tmp/file1  tmp/file2

doc:
index.html

tmp:
dir0  file1  file2

tmp/dir0:
file0

和 .gitignore 像这样:

# cat .gitignore
doc
tmp/*

这会忽略 doc 目录和 tmp 下面的所有文件。
Git 按预期工作,但列出被忽略文件的给定命令却没有。
让我们看看 git 怎么说:

# git ls-files --others --ignored --exclude-standard                                                            
tmp/file1
tmp/file2

请注意,列表中缺少 doc
您可以通过以下方式获取它:

# git ls-files --others --ignored --exclude-standard --directory                                                
doc/

注意附加的 --directory 选项。

据我所知,没有一个命令可以一次性列出所有被忽略的文件。
但我不知道为什么tmp/dir0根本不显示。

While generally correct your solution does not work in all circumstances.
Assume a repo dir like this:

# ls **/*                                                                                                       
doc/index.html  README.txt  tmp/dir0/file0  tmp/file1  tmp/file2

doc:
index.html

tmp:
dir0  file1  file2

tmp/dir0:
file0

and a .gitignore like this:

# cat .gitignore
doc
tmp/*

This ignores the doc directory and all files below tmp.
Git works as expected, but the given command for listing the ignored files does not.
Lets have a look at what git has to say:

# git ls-files --others --ignored --exclude-standard                                                            
tmp/file1
tmp/file2

Notice that doc is missing from the listing.
You can get it with:

# git ls-files --others --ignored --exclude-standard --directory                                                
doc/

Notice the additional --directory option.

From my knowledge there is no one command to list all ignored files at once.
But I don't know why tmp/dir0 does not show up at all.

老街孤人 2024-07-19 09:53:24

Git 现在内置了此功能

git check-ignore *

当然,您可以在您的情况下将 glob 更改为 **/*.dll

Git 参考

Git now has this functionality built in

git check-ignore *

Of course you can change the glob to something like **/*.dll in your case

Git Reference

晚雾 2024-07-19 09:53:24

以下是如何打印工作树中与 Git 的多个 gitignore 源中任意位置的模式相匹配的文件的完整列表(如果您使用的是 GNU find):

$ cd {your project directory}
$ find . -path ./.git -prune -o -print \
| git check-ignore --no-index --stdin --verbose

它将检查当前分支中的所有文件存储库的(除非您已在本地删除它们)。

它还标识了特定的 gitignore 源代码行。

Git 继续跟踪某些与 gitignore 模式匹配的文件中的更改,只是因为这些文件已被添加。 有用的是,上面的命令也显示这些文件。

负的 gitignore 模式也被匹配。 但是,这些在列表中很容易区分,因为它们以 ! 开头。

如果您使用的是 Windows,Git Bash 包含 GNU find (正如 find --version 所揭示的那样)。

如果列表很长(并且您有 rev),您也可以通过扩展名(某种程度上)显示它们:

$ cd {your project directory}
$ find . -path ./.git -prune -o -print \
| git check-ignore --no-index --stdin --verbose \
| rev | sort | rev

有关更多详细信息,请参阅 man findman git-check-ignore、man revman sort

整个方法的要点是 Git(软件)正在快速变化并且非常复杂。 相比之下,GNU 的 find 极其 稳定(至少在此处使用的功能方面是如此)。 因此,任何希望通过展示自己对 Git 的深入了解来提高竞争力的人都会以不同的方式回答这个问题。

最好的答案是什么? 这个答案故意最小化对 Git 知识的依赖,通过模块化(信息隔离)来实现稳定和简单的目标,并且被设计为可以持续很长时间

Here's how to print the complete list of files in the working tree which match patterns located anywhere in Git's multiple gitignore sources (if you're using GNU find):

$ cd {your project directory}
$ find . -path ./.git -prune -o -print \
| git check-ignore --no-index --stdin --verbose

It will check all the files in the current branch of the repository (unless you've deleted them locally).

And it identifies the particular gitignore source lines, as well.

Git continues to track changes in some files which match gitignore patterns, simply because those files were added already. Usefully, the above command displays those files, too.

Negative gitignore patterns are also matched. However, these are easily distinguishable in the listing, because they begin with !.

If you're using Windows, Git Bash includes GNU find (as revealed by find --version).

If the list is long (and you have rev), you can display them by extension (somewhat), too:

$ cd {your project directory}
$ find . -path ./.git -prune -o -print \
| git check-ignore --no-index --stdin --verbose \
| rev | sort | rev

For more details, see man find, man git-check-ignore, man rev, and man sort.

The point of this whole approach is that Git (the software) is changing rapidly and is highly complex. By contrast, GNU's find is extremely stable (at least, in its features used here). So, anyone who desires to be competitive by displaying their in-depth knowledge of Git will answer the question in a different way.

What's the best answer? This answer deliberately minimizes its reliance on Git knowledge, toward achieving the goal of stability and simplicity through modularity (information isolation), and is designed to last a long time.

甜味超标? 2024-07-19 09:53:24

使用它应该足够了,

git ls-files --others -i --exclude-standard

因为它涵盖了所涵盖的所有内容,

git ls-files --others -i --exclude-from=.git/info/exclude

因此后者是多余的。


You can make this easier by adding an alias to your ~/.gitconfig file:

git config --global alias.ignored "ls-files --others -i --exclude-standard"

现在您只需输入 gitignoreed 即可查看列表。 更容易记住,打字也更快。

如果您更喜欢 Jason Geng 的解决方案的更简洁显示,您可以为其添加一个别名,如下所示:

git config --global alias.ignored "status --ignored -s"

然而,更详细的输出对于解决 .gitignore 文件的问题更有用,因为它列出了每个单独的棉花采摘文件被忽略。 您通常会通过 grep 传送结果,以查看其中是否存在您希望忽略的文件,或者是否存在您不想忽略的文件。

git ignored | grep some-file-that-isnt-being-ignored-properly

然后,当您只想看到简短的显示时,很容易记住和键入

git status --ignored

(通常可以省略 -s。)

It should be sufficient to use

git ls-files --others -i --exclude-standard

as that covers everything covered by

git ls-files --others -i --exclude-from=.git/info/exclude

therefore the latter is redundant.


You can make this easier by adding an alias to your ~/.gitconfig file:

git config --global alias.ignored "ls-files --others -i --exclude-standard"

Now you can just type git ignored to see the list. Much easier to remember, and faster to type.

If you prefer the more succinct display of Jason Geng's solution, you can add an alias for that like this:

git config --global alias.ignored "status --ignored -s"

However the more verbose output is more useful for troubleshooting problems with your .gitignore files, as it lists every single cotton-pickin' file that is ignored. You would normally pipe the results through grep to see if a file you expect to be ignored is in there, or if a file you don't want to be ignore is in there.

git ignored | grep some-file-that-isnt-being-ignored-properly

Then, when you just want to see a short display, it's easy enough to remember and type

git status --ignored

(The -s can normally be left off.)

捶死心动 2024-07-19 09:53:24

如果您只需要有效的文件列表忽略(无论它们如何被忽略),并且没有任何额外的通知和日志。

一旦创建,任何地方(在Git-bash中) ) run:

git ignore-list

通过执行以下命令创建它:

git config --global alias.ignore-list "! cd -- \"\${GIT_PREFIX:-.}\" && git ls-files -v \${1:-.} | sed -n -e \"s,^[a-z] \(.*\)$,\${GIT_PREFIX:-./}\1,p\" && git status --ignored --porcelain \${1:-.} 2>/dev/null | sed -n -e \"s/^\(\\!\\! \)\(.*\)$/\2/p\" #"

使用示例,
假设这是初始提交并且您想要推送所有内容,请尝试:

git 忽略列表 |   xargs git add -f 
  

注意:

  1. 它已经过测试并且可以在 macOSWindows 平台上运行!
  2. 一旦您 cd 进入某个目录,仅列出该目录(或其子目录)中忽略的文件。
  3. 最后,始终记录相对于 root-dir 的路径(其中包含 .git 目录,无论您 cd 进入哪个目录)。

另一个有用的东西是人类可读性,就像如果忽略整个目录,例如 buildnode_modules,这将仅记录目录名称。
而 git ls-files --others -i --exclude-standard 命令会记录每个文件(适用于 xargs )。

If you just need a valid list of files ignored (no matter how they got ignored), and without any extra notice and logs.

Once created, anywhere (in Git-bash) run:

git ignore-list

Create it by executing:

git config --global alias.ignore-list "! cd -- \"\${GIT_PREFIX:-.}\" && git ls-files -v \${1:-.} | sed -n -e \"s,^[a-z] \(.*\)$,\${GIT_PREFIX:-./}\1,p\" && git status --ignored --porcelain \${1:-.} 2>/dev/null | sed -n -e \"s/^\(\\!\\! \)\(.*\)$/\2/p\" #"

Example usage,
Assuming it's the initial commit and you want to push everything, try:

git ignore-list | xargs git add -f

Notes:

  1. It's tested and works on both macOS and Windows platforms!
  2. Once you cd into a directory, lists only files ignored from that dir (or its sub-dirs).
  3. And lastly, always logs paths relative to root-dir (which contains .git dir, no matter what dir you cd into).

Another useful thing is Human-readability, like if an entire directory is ignored, something like build or node_modules, this will log dir-name only.
While git ls-files --others -i --exclude-standard command logs each and every file (good for xargs).

怎樣才叫好 2024-07-19 09:53:24

我只想

git status --porcelain --ignored

列出被忽略的文件

git status --porcelain --ignored | grep '^[!][!] '

I would just do

git status --porcelain --ignored

and to only list the ignored files

git status --porcelain --ignored | grep '^[!][!] '
迟月 2024-07-19 09:53:24

您可以使用 fd

运行的命令是:

comm -23 <(fd -HI | sort) <(fd -H | sort) 

请注意,如果没有 .git 目录,只有 .gitignore 文件(例如裸存储库),您必须具体说明位置.gitignore 文件是。

comm -23 <(fd -HI | sort) <(fd -H --ignore-file .gitignore | sort)

更具体地说,请使用 --no-ignore-vcs 而不是 -I

有关更多详细信息,请查看 此处

You can use fd.

The command to run is:

comm -23 <(fd -HI | sort) <(fd -H | sort) 

Please note that in case there is no .git directory and only a .gitignore file (ex. bare repo), you have to specifically tell where the .gitignore file is.

comm -23 <(fd -HI | sort) <(fd -H --ignore-file .gitignore | sort)

To be more specific, use --no-ignore-vcs instead of -I

For more details please check here.

凡间太子 2024-07-19 09:53:24

假设有一些忽略目录,为什么不使用“git status node/logs/”来告诉您要添加哪些文件? 在目录中,我有一个不属于状态输出的文本文件,例如:

Onbranchmaster
您的分支已更新为“origin/master”。
未跟踪的文件:
(使用“git add ...”包含在将提交的内容中)

    node/logs/.gitignore 

.gitignore 是:

*

!.gitignore

Assuming there are a few ignore directories, why not use "git status node/logs/" which will tell you what files are to be added? In the directory I have a text file that is not part of status output, e.g.:

On branch master
Your branch is up-to-date with 'origin/master'.
Untracked files:
(use "git add ..." to include in what will be committed)

    node/logs/.gitignore 

.gitignore is:

*

!.gitignore

双马尾 2024-07-19 09:53:24

(扩展其他答案)

注意,git check-ignore 使用提交的 .gitignore 而不是工作树中的! 要在不污染 git 历史记录的情况下使用它,您可以自由地尝试编辑它,然后使用 git commit --amend 进行提交。

这个问题主要发生在您需要解决问题的方法时,即 git 不跟踪目录。 在.gitignore中输入:

dirtokeep/**
!dirtokeep/.keep

.keep应该是dirtokeep中的零长度文件。

结果将是 dirtokeep 中的所有内容都将被忽略,除了 dirtokeep/.keep,这将导致dirtokeep 目录也将在克隆/签出时构建。

(extending the other answers)

Note, git check-ignore uses the committed .gitignore and not the one in your working tree! To play with it without polluting your git history, you might freely try to edit it, and then commit with a git commit --amend.

This problem happens mainly if you need a workaround of the problem, that git doesn't follow directories. Enter in the .gitignore:

dirtokeep/**
!dirtokeep/.keep

.keep should be a zero-length file in dirtokeep.

The result will be that everything in dirtokeep will be ignored, except dirtokeep/.keep, which will result that also the dirtokeep directory will be constructed on clone/checkout.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文