Gitで自分のローカルで使用しているファイルを追跡対象外にする方法

Git

gitを使用している時に、ローカルでは持っていたいけど、コミットしたくないファイルがあると思います。そういうファイルは個人用なので、.gitignoreにいちいち修正してコミットもしたくないという問題があります。
今回はコミット不要で.gitignoreのようにファイルの追跡対象外にする方法を紹介します。
解決策はGitリポジトリに「.git/info/exclude」ファイルを作成すれば解決します。
こちらのファイルに.gitignoreと同じように追跡対象外にしたいファイルを設定できます。

実際に試す

git statusをして、以下の様に「test04.txt」に変更が入っています。
今回は「test04.txt」を追跡対象外にしていきます。

% git status
On branch master
Your branch is up to date with 'origin/master'.

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

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

「.git/info/exclude」に「test04.txt」を記載する

test04.txt

もう一度「git status」をすると、「test04.txt」が追跡対象外になりました。

% git status
On branch master
Your branch is up to date with 'origin/master'.

nothing to commit, working tree clean

まとめ

.git/info/excludeを使用することで、ローカル専用の.gitignoreができること事を紹介しました。
このブログでは他にも駆け出しエンジニア向けに、Go言語の記事をあげています。
興味あればそちらも見ていただけたらと思います。

【おすすめ記事のリンク】

コメント

タイトルとURLをコピーしました

Fatal error: Uncaught JSMin_UnterminatedStringException: JSMin: Unterminated String at byte 868: "開発していて、自分のローカルで使用するだけのファイルがあって、Gitで管理したくはないけど、.gitignoreに入れるほどでもないということがあると思います。 in /home/c5287456/public_html/engineer-want-to-grow.com/wp-content/plugins/autoptimize/classes/external/php/jsmin.php:214 Stack trace: #0 /home/c5287456/public_html/engineer-want-to-grow.com/wp-content/plugins/autoptimize/classes/external/php/jsmin.php(152): JSMin->action(1) #1 /home/c5287456/public_html/engineer-want-to-grow.com/wp-content/plugins/autoptimize/classes/external/php/jsmin.php(86): JSMin->min() #2 /home/c5287456/public_html/engineer-want-to-grow.com/wp-content/plugins/autoptimize/classes/external/php/ao-minify-html.php(257): JSMin::minify('{"@context":"ht...') #3 [internal function]: AO_Minify_HTML->_removeScriptCB(Array) #4 /home/c5287456/public_html/engineer-want-to-grow.com/wp-content/plugins/autop in /home/c5287456/public_html/engineer-want-to-grow.com/wp-content/plugins/autoptimize/classes/external/php/jsmin.php on line 214