LoginSignup
0
0

More than 1 year has passed since last update.

【Git】.gitignoreでファイルを管理外にする メモ

Posted at

.gitignoreファイルとは??

Gitの管理外に置きたいファイルやフォルダを指定するための設定を行うファイルである

.gitignoreファイルの書き方

こちらの方の表が見やすかったのでお借りします
https://blog1.mammb.com/entry/2020/01/30/090000
image.png

  • 先頭を / で始めると .gitignore のあるディレクトリからの相対パス
  • 末尾が / の場合はディレクトリとして解釈される
  • コメント行は # で始める
  • ディレクトリ階層毎に複数配置可能で、階層の深いものが後から解釈される
  • git add した後で .gitignore に追加しても自動で消えはしない(git rm --cached で消す)`

実際にやってみる

1. ローカルリポジトリに適当なファイルを作る

touch example.txt

2. git statusで確認

$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        example.txt

nothing added to commit but untracked files present (use "git add" to track)

この段階では「example.txt」が新しく追加され、未追跡であることが表示されています。

3. .gitignoreファイルを作成し、中身を記述
フォルダの中に新しく.gitignoreファイルを作成します。
image.png

作成できたら、以下の様にexample.txtを指定します。
image.png

4. git statusで再度確認

$ git status
On branch master
Your branch is ahead of 'origin/master' by 2 commits.
  (use "git push" to publish your local commits)

Untracked files:
  (use "git add <file>..." to include in what will be committed)
        .gitignore

nothing added to commit but untracked files present (use "git add" to track)

example.txtをadd,commitをしていないですが、表示されなくなりました。
代わりに .gitignoreが表示されるようになりました。

このようにして、バージョン管理から外したいファイル(パスワードが記載されたもの)などを設定することができました。

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