# 【.gitignore】How to specify a path, what to do if it does not reflect, etc.

This article is a personal note related to .gitignore.

## Specify path

# ignore .txt hoge message
hoge.txt

# Ignore hoge directory
hoge/

# Ignore hoge directory
/hoge/

The directory ignored changes first by whether or not to add “/”.

If / is attached first, the directory specified in the relative path from .gitignore is ignored. If / is not attached first, all directories will be searched and the specified directory will be ignored.

## Wildcards and nega denying

# .txt all files in the file
*.txt

# Don't ignore hoge directories
!temp/

* can be used with all, and ! can be used for negation. You can also use ? and [0-9] can also be used.

## Specific extension files in a specific directory

# Ignore .txt files in hoge
hoge/**/*.txt

## When you edit .gitignore but it is not reflected

Causes and solutions for .gitignore but their edits are not reflected.

## Cause

It was due to the addition of something once uploaded to git to .gitignore. In short, I made a commit and pushed it before editing.

Apparently, the .gitignore setting was not reflected because there is still an index in the cache.

## Solution

### Steps

1. .gitignore Edit
2. Delete cache
3. commit & push

### Delete cache

# Delete entire file cache
$git rm -r --cached . # Delete cache by specifying a file$ git rm -r --cached [ファイル名]

Run the above command.

Ensure that the entire file cache is deleted. I haven’t thought of a point where I’m bothering to delete by specifying a file.

## Reference

[Git] .gitignoreの仕様詳解 - Qiita