跟踪忽略目录内的文件 [英] Track file inside ignored directory

查看:102
本文介绍了跟踪忽略目录内的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

前段时间,我将 .gitignore 文件设置为而不是跟踪文件夹 my_folder with:

  my_folder / 

现在我只想跟踪名为 my_file.md 的文件夹中的给定文件。使 .gitignore 看起来像这样:

  my_folder / 
!my_folder / my_file.md

并检查:

  git status 

文件不会显示为一个改变将被提交。



我做错了什么?




p>

  my_folder / * 
!my_folder / my_file.md

建议,但文件仍然没有显示为 git status 。我需要重置某些内容吗?






加2



尝试使用添加文件git add my_folder / my_file.md 返回:

 以下路径被一个.gitignore文件忽略:
my_folder / my_file.md
如果您真的想添加它们,请使用-f。
致命:没有添加文件

命令 git check-ignore -v my_folder / my_file.md 给出:

  .gitignore:1:my_folder / * my_folder / my_file.md 


解决方案

添加到 .gitignore 排除文件夹但包含特定子文件夹,这是调试这些文件的好方法。 gitignore文件是使用 git check-ignore (Git 1.8.4 +):

  git check-ignore -v my_folder / my_file.md 

您会发现它仍然被忽略,因为 my_folder / rule。



这是因为如果不包括该文件的父目录,则不可能重新包含文件。
* :除非在git 2中满足某些条件。$ +
$ b

这就是为什么忽略该文件夹中的文件 my_folder / * code $>,而不是文件夹本身)允许你排除一个。



当然,你可以强制添加一个被忽略的文件( git add -f my_folder / my_file.md ),但这不是这个答案的要点。

这一点是解释为什么添加!my_folder /my_file.md .gitignore 中不适用于git 2.6或更低版本。



< hr>

请注意,使用git 2.9.x / 2.10(2016年中期?),如果该文件的父目录被排除,那么可能会重新包含一个文件如果在重新包含的路径中没有通配符



NguyễnTháiNgọcDuy( pclouds 试图添加th是功能:



所以,在这里,使用git 2.8+,这是可行的:

  / my_folder 
!my_folder / my_file.md


Some time ago I set up my .gitignore file to not track a folder my_folder with:

my_folder/

Now I want to track only a given file inside said folder, named my_file.md. After making .gitignore look like this:

my_folder/
!my_folder/my_file.md

and checking:

git status

the file does not appear as a change to be committed.

What am I doing wrong?


Add

I tried changing my .gitignore file to:

my_folder/*
!my_folder/my_file.md

as advised but the file is still not showing up as a change to commit after a git status. Do I need to reset something?


Add 2

Attempting to add the file with git add my_folder/my_file.md returns:

The following paths are ignored by one of your .gitignore files:
my_folder/my_file.md
Use -f if you really want to add them.
fatal: no files added

The command git check-ignore -v my_folder/my_file.md gives:

.gitignore:1:my_folder/*    my_folder/my_file.md

解决方案

To add to ".gitignore exclude folder but include specific subfolder", one good way to debug those .gitignore file is to use git check-ignore (Git 1.8.4+):

git check-ignore -v my_folder/my_file.md

You would see it is still ignored because of the my_folder/ rule.

That is because 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.?+, see below)

That is why ignoring the files within that folder (my_folder/*, instead of the folder itself) allows you to exclude one.

Of course, you can force adding a file ignored (git add -f my_folder/my_file.md), but that is not the point of this answer.
The point is to explain why adding !my_folder/my_file.md in .gitignore doesn't work with git 2.6 or less.


Note that with git 2.9.x/2.10 (mid 2016?), it might be possible to re-include a file if a parent directory of that file is excluded if there is no wildcard in the path re-included.

Nguyễn Thái Ngọc Duy (pclouds) is trying to add this feature:

So here, with git 2.8+, this would work:

/my_folder
!my_folder/my_file.md

这篇关于跟踪忽略目录内的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆