git update-index

git

書き方

git update-index [--skip-worktree|--chmod=+x] <file>

索引を直接いじります。この印はローカル限りでpushされず、追跡中の設定ファイルに自分の変更を残したいときは--assume-unchangedではなく--skip-worktreeです。

よく使うオプション

オプション意味
--chmod=+xrecord the executable bit, useful from Windows
--skip-worktreelet you keep local edits to a tracked file
--no-skip-worktreeundo that
--assume-unchangedpromise you will not edit it, as a speed hint only
--no-assume-unchangedundo that
--refreshupdate stat information after a filesystem change

git update-index --chmod=+x scripts/deploy.sh

stages the executable bit so CI can run it

git update-index --skip-worktree config/local.json

keeps your local edits out of every diff

git update-index --no-skip-worktree config/local.json

puts the file back under normal tracking

取り消しに何通りもあるのが混乱のもとです — ブランチの指す先を動かすのと、打ち消すコミットを積むのは別です。

読み方

  • 角括弧 [ ] は省いてよい部分です。
  • 三点 … は複数並べられるという意味です。
  • オプションは大文字小文字を区別します — -r と -R が別物のコマンドもあります。

よくある質問

Q. git update-index は何をしますか。

索引を直接いじります。この印はローカル限りでpushされず、追跡中の設定ファイルに自分の変更を残したいときは--assume-unchangedではなく--skip-worktreeです。

Q. どう打ちますか。

git update-index [--skip-worktree|--chmod=+x] <file> — 角括弧は省いてよい部分です。

Q. よく使うオプションはいくつですか。

ここにまとめたのは6個です。全部は man git にあります。このコマンドはgitの仲間です。

関連するコマンド

man ページ: man git-update-index