LoginSignup
73
62

More than 3 years have passed since last update.

gitの除外したいファイルをローカルでのみ適用する(.vscode の設定を例に)

Last updated at Posted at 2018-10-29
  • 複数人で開発しているときに.gitignoreに入れるほどではないけど、自分のローカルで生成されてしまったファイルやディレクトリをgitの管理対象から恒常的に除外したくなるケースがある。
  • 例えば自分だけVSCodeを使っていて、.gitignoreには追記するほどではないけど、自分の環境でのみ .vscode ディレクトリをgit の管理から除外したい場合。
  • プロジェクトのディレクトリで下記コマンドを実行する。

やっていることは、ローカルの .git ディレクトリにあるファイルに除外したいファイルやディレクトリを追記するということをしている。

$ ls                                                                                                                                                              
Dockerfile          README.md           bin                 db                  log                 public              tmp
Gemfile             Rakefile            config              docker-compose.yaml node_modules        spec                vendor
Gemfile.lock        app                 config.ru           lib                 package.json        test

$ echo .vscode/* >> .git/info/exclude

$ cat .git/info/exclude
# git ls-files --others --exclude-from=.git/info/exclude
# Lines that start with '#' are comments.
# For a project mostly in C, the following would be a good set of
# exclude patterns (uncomment them if you want to use them):
# *.[oa]
# *~
.vscode/settings.json

.gitignoreに追加する場合(本件とは関係ないおまけ)

.gitignoreファイルに下記を追記

.vscode/*

参考:
gitで常に.vscodeを無視する
Git | excludeファイルにローカル環境だけ無視したいファイルを登録

73
62
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
73
62