Git:子目录中的.gitignore

编程入门 行业动态 更新时间:2024-10-14 12:26:16
本文介绍了Git:子目录中的.gitignore的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试使用git管理我的 neovim 的 init.vim 。 我想忽略除

I'm trying to manage my neovim's init.vim with git. I want to ignore everything except the init.vim in the same folder as the .gitignoreand one kalisi.vim in the directory

/ bundle / vim-airline / autoload / airline / themes /

这是我当前的 .gitignore :

This is my current .gitignore:

# Ignore everything * # Exceptions !.gitinore !init.vim !bundle bundle/* !bundle/vim-airline bundle/vim-airline/* !bundle/vim-airline/autoload bundle/vim-airline/autoload/* !bundle/vim-airline/autoload/airline bundle/vim-airline/autoload/airline/* !bundle/vim-airline/autoload/airline/themes bundle/vim-airline/autoload/airline/themes/* !bundle/vim-airline/autoload/airline/themes/kalisi.vim

我对此的看法:

  • 忽略所有内容: *

除此 .gitignore : !. gitgnore

init.vim 在同一目录中:!init.vim

也不要忽略文件夹 bundle :!bundle

但是其中的所有内容: bundle / *

But everything in it: bundle/*

除了文件夹 vim-airline :!vim-airline

我想你明白了...

但是如果我执行 git状态现在仅获得 bundle / 作为未跟踪文件。我不应该得到 kalisi.vim 或 bundle / vim-airline / autoload / airline / themes / kalisi.vim ?

But if I execute git status now only get bundle/ as untracked file. Should't I get kalisi.vim or bundle/vim-airline/autoload/airline/themes/kalisi.vim?

我希望能有一种更优雅的坦率方式。我还听说过要在目录中放置多个 .gitignore ,但是子目录都是具有自己的 .gitignore ,这将产生大量工作,而只是不忽略正确的 .gitignore 。

I'm hoping for a more elegant way to be honest. I also heard about placing multiple .gitignore's in the directories, but the subdirectories are all projects with it's own .gitignore and this would create a huge amount of work to only not-ignore the right .gitignore.

我希望有人知道该怎么做,目前看来好像跟踪了 bundle / 目录,但不是我想要的内容...

I hope someone has an idea what to do, currently it just seems like the bundle/ directory is tracked, but not the content I want...

推荐答案

正如我在 如何将文件中没有点的文件(所有无扩展名的文件)添加到gitignore文件中?,使用要记住一个规则。 gitignore :

无法重新-包括文件(如果排除该文件的父目录)。 ( † ) ( † :除非在git 2.7+中满足某些条件,否则

It is not possible to re-include a file if a parent directory of that file is excluded. (†) (†: unless certain conditions are met in git 2.7+)

这意味着,当您排除所有内容时(' * '),您必须先将文件夹白名单(' / ** / '),然后才能将文件白名单。

That means, when you exclude everything ('*'), you have to white-list folders ('/**/'), before being able to white-list files.

# Ignore everything * # Exceptions !.gitinore !init.vim !/**/ !bundle/vim-airline/autoload/airline/themes/kalisi.vim

OP LastSecondsToLive 实际上采用了一种更简单的方法:

The OP LastSecondsToLive actually took a simpler approach:

我使用 bundle / vim-airline / autoload / airline / themes / kalisi.vim 创建了一个提交我将 .gitignore 切换回: *!.gitinore!init.vim 忽略所有内容,但是由于 bundle / vim-airline / autoload / airline / themes / kalisi.vim 已被跟踪,更改将在f中被跟踪未来

I created a commit with bundle/vim-airline/autoload/airline/themes/kalisi.vim then I switched my .gitignore back to:* !.gitinore !init.vim to ignore everything, but since bundle/vim-airline/autoload/airline/themes/kalisi.vim is already tracked, changes will get tracked in the future.

更多推荐

Git:子目录中的.gitignore

本文发布于:2023-11-01 13:23:12,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1549437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:目录中   Git   gitignore

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!