2

ディレクトリ内の 1 つのファイルを除くすべてのファイルを無視したい。

私はgit bashで次のことを行います。

$ mkdir dir_to_ignore
$ cd dir_to_ignore
$ vi file_to_ignore.txt 
# (I put some content and save the file)
$ vi second_file.txt
# (Some text and then save the file. I dont wish this file to be ignored)
$ cd ..
$ vi .gitignore 

次の内容を.gitignoreファイルに入れました。

dir_to_ignore/
!dir_to_ignore/second_file.txt

しかし、今では、追跡されていないファイルとしてgit status表示second_file.txtされません。なぜこうなった?

4

3 に答える 3

4

ディレクトリを無視するのに、無視されたディレクトリ内のファイルを追跡しようとするのは、ちょっと奇妙に思えます。なぜなら、ファイルを追跡するには、ファイルが存在するディレクトリを含め、ファイルへのフル パスを知る必要があるからです。

.gitignore代わりにファイルを次のように変更すると:

dir_to_ignore/*
!second_file.txt

dir_to_ignoreを除く下のすべてのファイルを無視しますsecond_file.txt。ただし、ディレクトリも追跡するには、ディレクトリを追跡する必要がありますsecond_file.txt

于 2013-05-25T02:28:40.003 に答える
2

.gitignoreディレクトリにファイルを作成し、dir_to_ignoreこれをその中に入れることで、必要なものを達成できます

*
!second_file.txt
!.gitignore

.gitignore(おそらく新しいファイルもバージョン管理したいと仮定します)

于 2013-05-25T02:25:42.350 に答える