誰にも見えないブログ

雑なメモ。まとまってない文章等

【git】ステージングの取り消し

  • git add .とかで不要なステージングが発生したときのメモ。
$ touch a.txt
$ touch b.txt
$ git init
Initialized empty Git repository in .git/
$ git add .
$ ls
a.txt  b.txt
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   a.txt
    new file:   b.txt
  • a.txtはgitで管理したくないとする。*1
  • git rm --chace <file>でステージングから削除可能
    • --chaceをつけないとステージングだけでなくファイル本体も削除される
$ git rm --cached a.txt
rm 'a.txt'
$ ls
a.txt  b.txt
$ git status
On branch master

No commits yet

Changes to be committed:
  (use "git rm --cached <file>..." to unstage)

    new file:   b.txt

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

    a.txt

$ 
  • a.txtがステージングされていない状態に戻ったことが確認できました。

*1:本来ならばignoreファイルで扱うべきだが