概要
ファイルの削除
詳細
git では以下の2種類の方法でファイルを削除します。
$ git rm remove_file
これは、以下と同じです。
rm remove_file git add remove_file
サンプル(git rm)
$ git init $ echo hoge > hoge.txt $ git add -A $ git commit -m "add hoge.txt" [master (root-commit) 705d261] add hoge.txt 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 hoge.txt $ git rm hoge.txt rm 'hoge.txt' $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: hoge.txt # $ git commit -m "delete hoge.txt" [master 2bf0182] delete hoge.txt 1 files changed, 0 insertions(+), 1 deletions(-) delete mode 100644 hoge.txt $ git status # On branch master nothing to commit (working directory clean)
サンプル(rm)
$ git init $ echo hoge > hoge.txt $ git add -A $ git commit -m "add hoge.txt" [master (root-commit) 2e34c58] add hoge.txt 1 files changed, 1 insertions(+), 0 deletions(-) create mode 100644 hoge.txt $ rm hoge.txt $ git status # On branch master # Changes not staged for commit: # (use "git add/rm <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # deleted: hoge.txt # no changes added to commit (use "git add" and/or "git commit -a") $ git add -A $ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: hoge.txt # $ git commit -m "delete hoge.txt" [master 0a8653a] delete hoge.txt 1 files changed, 0 insertions(+), 1 deletions(-) delete mode 100644 hoge.txt $ git status # On branch master nothing to commit (working directory clean)