git の監視から逃れる方法
既に追跡されている
追跡の必要性がなくなった場合
ファイルを削除 & インデックスから削除して commit
git rm path/to/file
git commit -m 'Good-bye file'
なお, ファイルを残したまま追跡から逃れたいときは git rm --cached path/to/file
でインデックスのみ削除し, .gitignore
などで指定する. また, 誤って git rm
してしまったときは git reset @~ path/to/file
, git checkout path/to/file
で回復する.
ローカルでのみ追跡してほしくない場合
二つ方法がある. これらの違いは既に git 管理しているファイルをあえて無視したい - Qiitaに詳しい.
用途に依るが, assume-unchanged
の変更は git reset --hard
で死ぬので, 基本的には skip-worktree
を使う.
assume-unchanged
除外するとき
git update-index --assume-unchanged path/to/file
除外から戻すとき
git update-index --no-assume-unchanged path/to/file
確認するとき
git ls-files -v | grep ^h
skip-worktree
除外するとき
git update-index --skip-worktree path/to/file
除外から戻すとき
git update-index --no-skip-worktree path/to/file
確認するとき
git ls-files -v | grep ^S
まだ追跡されていない
プロジェクト単位で追跡してほしくない場合
.gitignore
に記述する.
ローカルでのみ追跡してほしくない
対象リポジトリのみで追跡から逃れる場合
.git/info/exclude
に記述する.
ローカルの全リポジトリで追跡から逃れる場合
ホームディレクトリに .gitignore
を用意する (今回は区別のため .gitignore_global
とした.)
*~
*.swp
*.swo
.DS_Store
*~
*#
.#*
git の global 設定に保存する
git config --global core.excludesfile $HOME/.gitignore_global
上のコマンドにより, 以下のように設定が ~/.gitconfig
に反映される.
[core]
excludesfile = /home/{ユーザー名}/.gitignore_global
References
Author And Source
この問題について(git の監視から逃れる方法), 我々は、より多くの情報をここで見つけました https://qiita.com/sqrtxx/items/38a506e59df67cd5d3a1著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .