如何添加带有变量结尾(“扩展名”)的.gitignore文件,但开头是一样的

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了如何添加带有变量结尾(“扩展名”)的.gitignore文件,但开头是一样的相关的知识,希望对你有一定的参考价值。

StackOverflow社区!我不能忽略具有特定名称的文件:list.vtk.1,list.vtk.2,list.vtk.3等。我尝试将list.vtk。*添加到.gitignore,但它不起作用。我输入git status时会看到文件。如何处理变量扩展?

在.gitignore:

# data files
out
*.vtk
list.vtk.*
log.*
*.log
*log
.idea
dump-*

输出是

On branch master
Your branch is ahead of 'origin/master' by 1 commit.
  (use "git push" to publish your local commits)

Changes to be committed:
  (use "git reset HEAD <file>..." to unstage)

    new file:   2phase_new/Makefile
    new file:   embed_2phase/embed_2phase.c
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.0
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.1
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.10
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.11
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.12
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.13
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.14
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.15
    new file:   two_phase_flow_cylinders/results/Ox=10_No_BC_effects/list.vtk.16

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   ../.gitignore
    deleted:    two_phase_flow_cylinders/results/Oy mmm/list.vtk.0
    deleted:    two_phase_flow_cylinders/results/Oy mmm/list.vtk.1
    deleted:    two_phase_flow_cylinders/results/Oy mmm/list.vtk.10


Untracked files:
  (use "git add <file>..." to include in what will be committed)

    ../scratch.cpp
    2phase_new/parout
    2phase_new/results/manycyls_front/flow.avi
    2phase_new/results/manycyls_front/flow.mp4
    paraview/reserve
    reversed_3f-implicit/diff
    reversed_3f-implicit/f2
    reversed_3f-implicit/f3
答案

你的.gitignore模式list.vtk.*工作得很好,但是

  • 在添加该模式之前,您已在其中一些文件上调用了git add。因此他们被列为new file。像git本身所暗示的那样做一个git reset HEAD <file>
  • 在添加模式之前已经提交了三个其他文件,但现在已丢失。它们被列为deleted。像git本身所暗示的那样做一个git rm <file>

.gitignore机制仅适用于将在Untracked files:部分列出的文件。一旦跟踪它们,.gitignore就不再适用了。

以上是关于如何添加带有变量结尾(“扩展名”)的.gitignore文件,但开头是一样的的主要内容,如果未能解决你的问题,请参考以下文章

如何匹配可以以查询字符串结尾的 url 中的文件扩展名?

导入路径不能以“.ts”扩展名结尾。考虑导入'src/theme.js'

Regex-所有不带.html扩展名的PHP文件

如何将具有特定扩展名的文件添加到化石存储库中?

如何连接文件名和扩展名字符串? [复制]

如何将它们添加到字典中,并在python中每5个循环后使活动变量成为结尾?