是否有命令将 "roll up" 一棵 gitignores 树变成一个 parent gitignores?
Is there a command to "roll up" a tree of gitignores into one parent gitignore?
随着时间的推移,这个大型项目已经获得了很多分散在其许多目录中的 .gitignore 文件。当您处理一些新的输出文件夹或其他东西时,“在站点”添加一个新的 .gitignore 非常方便,但很难推理。
有没有办法将所有这些不同的 .gitignore 文件“卷起”回项目根目录的 .gitignore 中?最终结果将是一个单一的 .gitignore 文件。 gitignore project-wide,删除所有其他 ad-hoc。
如果我可以一次卷起一个子树,或者卷起一个公共子树,那将是特别的 child,这样我可以更有效地管理更改,但我不会挑剔。
具体例子:
之前:
root
|- .gitignore
|- subdir1
| |- .gitignore
| |- subdir3
| |- .gitignore
| |- ignored_file.txt
|- subdir2
|- .gitignore
# the .gitignore in subdir3
/ignored_file.txt
之后:
root
|- .gitignore
|- subdir1
| |- subdir3
| |- ignored_file.txt
|- subdir2
# the .gitignore in root
/subdir1/subdir3/ignored_file.txt
感谢您的宝贵时间!
标准 linux find
命令(或其更新的兄弟命令 fd
)将为您列出文件:
$ find * -name .gitignore
.gitignore
subdir1/.gitignore
subdir1/subdir3/.gitignore
subdir2/.gitignore
如果您有扩展 .gitignore
文件的脚本:
# write a script, which takes a path as input,
# and prefixes all patterns found within the file with 'path/' :
$ expand.py subdir1/subdir3/.gitignore
/subdir1/subdir3/ignored_file.txt
您可以将两者结合使用:
$ find * -name .gitignore | xargs -L1 expand.py
# look only in the subdir1 subdirectory :
$ find subdir1/ -name .gitignore | xargs -L1 expand.py
随着时间的推移,这个大型项目已经获得了很多分散在其许多目录中的 .gitignore 文件。当您处理一些新的输出文件夹或其他东西时,“在站点”添加一个新的 .gitignore 非常方便,但很难推理。
有没有办法将所有这些不同的 .gitignore 文件“卷起”回项目根目录的 .gitignore 中?最终结果将是一个单一的 .gitignore 文件。 gitignore project-wide,删除所有其他 ad-hoc。
如果我可以一次卷起一个子树,或者卷起一个公共子树,那将是特别的 child,这样我可以更有效地管理更改,但我不会挑剔。
具体例子:
之前:
root
|- .gitignore
|- subdir1
| |- .gitignore
| |- subdir3
| |- .gitignore
| |- ignored_file.txt
|- subdir2
|- .gitignore
# the .gitignore in subdir3
/ignored_file.txt
之后:
root
|- .gitignore
|- subdir1
| |- subdir3
| |- ignored_file.txt
|- subdir2
# the .gitignore in root
/subdir1/subdir3/ignored_file.txt
感谢您的宝贵时间!
标准 linux find
命令(或其更新的兄弟命令 fd
)将为您列出文件:
$ find * -name .gitignore
.gitignore
subdir1/.gitignore
subdir1/subdir3/.gitignore
subdir2/.gitignore
如果您有扩展 .gitignore
文件的脚本:
# write a script, which takes a path as input,
# and prefixes all patterns found within the file with 'path/' :
$ expand.py subdir1/subdir3/.gitignore
/subdir1/subdir3/ignored_file.txt
您可以将两者结合使用:
$ find * -name .gitignore | xargs -L1 expand.py
# look only in the subdir1 subdirectory :
$ find subdir1/ -name .gitignore | xargs -L1 expand.py