跟踪忽略目录内的文件 [英] Track file inside ignored directory
问题描述
前段时间,我将 .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 $ c之后的提交更改$ C>。我需要重置某些内容吗?
加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.9.x / 2.10(2016年中期?),如果该文件的父目录被排除,那么可能会重新包含一个文件如果在重新包含的路径中没有通配符。 NguyễnTháiNgọcDuy( 所以,在这里,使用git 2.8+,这是可行的: Some time ago I set up my Now I want to track only a given file inside said folder, named and checking: the file does not appear as a change to be committed. What am I doing wrong? Add I tried changing my as advised but the file is still not showing up as a change to commit after a Add 2 Attempting to add the file with The command
To add to " You would see it is still ignored because of the That is because it is not possible to re-include a file if a parent directory of that file is excluded.( That is why ignoring the files within that folder ( Of course, you can force adding a file ignored ( 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 ( So here, with git 2.8+, this would work:
这篇关于跟踪忽略目录内的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
( *
:除非在git 2中满足某些条件。$ +
$ b my_folder / * code $>,而不是文件夹本身)允许你排除一个。
git add -f my_folder / my_file.md
),但这不是这个答案的要点。
这一点是解释为什么添加!my_folder /my_file.md
在 .gitignore
中不适用于git 2.6或更低版本。
< hr>
pclouds
)试图添加th是功能:
/ my_folder
!my_folder / my_file.md
.gitignore
file to not track a folder my_folder
with:my_folder/
my_file.md
. After making .gitignore
look like this:my_folder/
!my_folder/my_file.md
git status
.gitignore
file to:my_folder/*
!my_folder/my_file.md
git status
. Do I need to reset something?
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
git check-ignore -v my_folder/my_file.md
gives:.gitignore:1:my_folder/* my_folder/my_file.md
.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
my_folder/
rule.*
)
(*
: unless certain conditions are met in git 2.?+, see below)my_folder/*
, instead of the folder itself) allows you to exclude one.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.
pclouds
) is trying to add this feature:
/my_folder
!my_folder/my_file.md