0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

特定のディレクトリ以下のファイルを全部 ignore だけどこれは除く。からのサブディレクトリのこれを除くって時の gitignore

0
Posted at

特定のディレクトリ以下のファイルは git に入れたくない

そのディレクトリの親ディレクトリの .gitignore にそのディレクトリを追加

.
└─work
  ├─Sources
  └─memo
   unko.txt
.gitignore
## Ignore memo directory
/memo/

そんなことしたら memo ディレクトリがあるってバレるじゃん。毎回 git add からはじく手間もあるし。

memo ディレクトリの .gitignore で対処

memo/.gitignore
## Ignore all file.
*

あ、やっぱりこのファイルだけ追加。memo ディレクトリも commit する。

.
└─work
  ├─Sources
  └─memo
    .gitignore
    memo.md             ## commit したい
    memo-image.png      ## commit したい
   unko.txt            ## 💩
memo/.gitignore
## Ignore all file, except markdown and images.
*
!.gitignore
!*.md
!*.png

なんかいろいろ増えてきたなぁ・・・ディレクトリ分けしよ

.
└─work
  ├─Sources
  └─memo
   └─memo1
     memo1.md          ## commit したい
      memo1-image.png   ## commit したい
   └─memo2
   └─memo3
   └─memo4
   └─memo5
    .gitignore
   unko.txt            ## 💩
memo/.gitignore
## Ignore all file, except markdown and images under this directory.
*
!.gitignore
!*.md
!*.png

・・・あれ?

$ find . -type f | xargs git check-ignore
./memo1/memo1-image.png
./memo1/memo1.md
./memo2/memo2.md
./memo3/memo3.md
./memo4/memo4.md
./memo5/memo5.md
./unko.txt

サブディレクトリ以下の *.md まではじかれちゃった・・・

.gitignore を修正

memo/.gitignore
## Ignore all file, except markdown and images under this directory.
*
!*/
!.gitignore
!*.md
!*.png
$ find . -type f | xargs git check-ignore
./unko.txt

にっこり(◍>◡<◍)g✧♡

参照
https://git-scm.com/docs/gitignore/ja

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?