記事のバージョン: GitHub.com
ファイルを無視する
You can configure Git to ignore files you don't want to check in to GitHub.
Configuring ignored files for a single repository
You can create a .gitignore file in your repository's root directory to tell Git which files and directories to ignore when you make a commit. To share the ignore rules with other users who clone the repository, commit the .gitignore file in to your repository.
GitHub maintains an official list of recommended .gitignore files for many popular operating systems, environments, and languages in the github/gitignore public repository. gitignore.io ファイルを使用して、お使いのオペレーティング システム、プログラミング言語、または IDE に応じた .gitignore ファイルを作成することもできます。 For more information, see "github/gitignore" and the "gitignore.io" site.
- ターミナルターミナルGit Bashを開いてください。
- Navigate to the location of your Git repository.
- Create a .gitignore file for your repository.
$ touch .gitignore
For an example .gitignore file, see "Some common .gitignore configurations" in the Octocat repository.
If you want to ignore a file that is already checked in, you must untrack the file before you add a rule to ignore it. From your terminal, untrack the file.
$ git rm --cached ファイル名
Configuring ignored files for all repositories on your computer
You can also create a global .gitignore file to define a list of rules for ignoring files in every Git repository on your computer. たとえば、~/.gitignore_global にファイルを作成し、そこにルールを追加することができます。
- ターミナルターミナルGit Bashを開いてください。
- Configure Git to use the exclude file ~/.gitignore_global for all Git repositories.
$ git config --global core.excludesfile ~/.gitignore_global
Excluding local files without creating a .gitignore file
他のユーザと共有される .gitignore ファイルを作成したくない場合は、リポジトリにコミットされないルールを作成することもできます。 ローカルで生成され、他のユーザが生成することは想定されないファイル、たとえば自分のエディターで作成されるファイルなどを無視するときに使える方法です。
使い慣れたテキストエディターを使って、Git リポジトリのルートにある .git/info/exclude というファイルを開きます。 ここで追加するルールはチェックインされないので、ローカル リポジトリにあるファイルだけが無視されます。
- ターミナルターミナルGit Bashを開いてください。
- Navigate to the location of your Git repository.
- 使い慣れたテキストエディターを使って、.git/info/exclude ファイルを開きます。
参考リンク
- Ignoring files in the Pro Git book
- .gitignore in the man pages for Git
- A collection of useful .gitignore templates in the github/gitignore repository
- gitignore.io site