追跡していないファイルと無視ファイル

追跡しないままのファイルはリポジトリの歴史には残らないが、gitの影響を受けず普通にディレクトリに存在し続ける

流れを確認するシェルスクリプト

  1. リポジトリ作成
  2. コミットして、リポジトリの状態確認
  3. 非追跡ファイル、無視ファイル、.gitignore作成して、リポジトリの状態確認
#!/bin/bash

# 一時ディレクトリを作り直す
rm -fr git-tmp; mkdir git-tmp; cd git-tmp
# スクリプト表示しながら実行
set -v

#--------------------------------------
# リポジトリ作成: repo
mkdir repo
cd repo
git init


#--------------------------------------
# コミット
echo 'A' >> abc
git add abc
git commit -m 'A'


# リポジトリの状態
git status


#--------------------------------------
# 追跡していないファイル
touch 非追跡ファイル 無視ファイル
echo '無視ファイル' >> .gitignore
ls


# リポジトリの状態
git status

実行結果

#--------------------------------------
# リポジトリ作成: repo
mkdir repo
cd repo
git init
Initialized empty Git repository in /home/alice/git-tmp/repo/.git/


#--------------------------------------
# コミット
echo 'A' >> abc
git add abc
git commit -m 'A'
[master (root-commit) d86303a] A
 1 file changed, 1 insertion(+)
 create mode 100644 abc


# リポジトリの状態
git status
# On branch master
nothing to commit, working directory clean


#--------------------------------------
# 追跡していないファイル
touch 非追跡ファイル 無視ファイル
echo '無視ファイル' >> .gitignore
ls
abc  非追跡ファイル  無視ファイル


# リポジトリの状態
git status
# On branch master
# 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)