1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

PowerShellでgitignoreが効かない

Posted at

はじめに

PowerShellでgitコマンド叩いてて、

git init
echo "close.txt" > .gitignore

としても.gitignore が有効にならないので相当ハマった。

同じことで悩んでいる人向けに情報共有

原因は文字コード

PowerShellのversion5以前ではリダイレクト処理の文字コードがBOM付きUTF16になる。これが原因で.gitignoreが上手く機能していなかた。

解決法

PowerShellのversion確認は、$PSVersionTable コマンドを表示する。単にterminalにこの文字を打てばよい。version 5.XだったらUTF16が原因である可能性がある。

PowerShell core のversion 6以降をインストールする。もしくはgit bashなど別のbashシステムを使う。

※注意

WSLを使いたいところですが、ファイルIOが低速ゆえに、シェルスクリプト等を組んでgitコマンドを流すと、checkout系の切り替えに実際のディスク上のファイル変更が間に合わず、エラーになることがあります。しかもIOのタイミングで結果が変わってしまうので問題の再現性が見られず、相当悩みます。gitを使うのはWSL2まで待った方がよさそうです。

1
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?