消したファイルのgitでの扱い方
Railsのアプリとかで、$ rails destroy model hogeとかして、hoge.rbとかのファイルを削除した場合に、その後、$ git add .すると、Gitさんからおらああああああ、って言われたので、確認した話。
Gitから言われた内容。
warning: You ran 'git add' with neither '-A (--all)' or '--ignore-removal', whose behaviour will change in Git 2.0 with respect to paths you removed. Paths like 'app/assets/javascripts/beginner_messages.js.coffee' that are removed from your working tree are ignored with this version of Git. * 'git add --ignore-removal <pathspec>', which is the current default, ignores paths you removed from your working tree. * 'git add --all <pathspec>' will let you also record the removals. Run 'git status' to check the paths you removed from your working tree.
→
$ git add --ignore-removalでは、消したファイルはignoreする(つまり消したってgit上では記録されない)
→
$ git add --allでは、git上でも消したと認識される
(つまり、これがほしいやつ!)
でさらに、調べると、
$ git add -Aが、$ git add . と$ git add -allをまとめてやってくれる模様!(これだ!)
参考:git add -A と git add . と git add -u の違い
$ git add -Aをする前
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # modified: views/uhos/index.html.erb # # 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: app/models/hoge.rb # deleted: db/migrate/33324_create_hoge.rb
$ git add -A後
# On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # deleted: app/models/hoge.rb # deleted: db/migrate/33324_create_hoge.rb
ちゃんと中に入ってる!
これでコミットしたらOK!
さらりとアドバイスくれた某A氏に多謝。