0
1

More than 3 years have passed since last update.

【Git】git addの取り消し方法

Posted at

プログラミング勉強日記

2021年3月23日

git addの取り消し方法

ファイル・ディレクトリを指定して取り消す

addの取り消し方法
$ git reset HEAD ファイル名/ディレクトリ名

addしたすべてのファイル・ディレクトリを取り消す方法

addしたときに追加されるすべてのファイルを取り消す
$ git reset HEAD .

一番最初のaddを取り消す方法

一番最初に実行したgit addを取り消したい場合は、HEADの参照がないのでgit restが使えない。なので、以下の方法で行う。

$ git rm --cached ファイル名・ディレクトリ
ディレクトリ内のすべてのaddを取り消す
$ git rm --cached -r ディレクトリ名

<注意>
git rm 〇〇でキャッシュを付け忘れると、どこにも保存していないファイル自体を消してしまう。なので、--cachedオプションを必ず付ける。

参考文献

git add の取り消し、add したファイルを戻す git reset のやり方
git add の取り消し方法と、関連コマンドまとめ

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