git status"を実行したところ、以下のように変更されたファイルや、"changes not staged for commit"という見出しで表示されたファイルがありました。 また、無視したいトラックされていないファイルもいくつか表示されました (これらのディレクトリには ".gitignore" ファイルを置いています)。
変更したファイルをステージングに置いてコミットできるようにしたいのです。 git add .quot;を実行したところ、変更したファイルと無視したいファイルがステージングに追加されました。
修正されたファイルだけを追加し、トラックされていないファイルを無視するにはどうしたらよいでしょうか。
また、私の ".gitignore" ファイルは正しく動作していますか?
$ git status
# On branch addLocation
# Changes not staged for commit:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: someProject/path/domain/viewer/LocationDO.java
# modified: someProject/path/service/ld/LdService.java
# modified: someProject/path/service/ld/LdServiceImpl.java
# modified: someProject/path/web/jsf/viewer/LocationFormAction.java
# modified: someProject/war/WEB-INF/classes/message/viewer/viewer.properties
# modified: someProject/war/page/viewer/searchForm.xhtml
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# .metadata/
# someProject/build/
no changes added to commit (use "git add" and/or "git commit -a")
理想的には、.gitignore
は追跡されていない (そして無視されている) ファイルがステータスに表示されたり git add
で追加されたりするのを防ぐべきです。ですから、あなたの .gitignore
を修正するようお願いします。
git add -u` を実行すると、変更されたファイルや削除されたファイルが表示されるようになります。
また、git commit -a
を実行すれば、変更されたファイルと削除されたファイルだけをコミットすることができます。
なお、Gitのバージョンが2.0より前で、git add .
を使用していた場合は、git add -u .
を使用する必要があります("「git add -A
」と「git add .
」の違い" 参照)。
これは私には有効でした。
#!/bin/bash
git add `git status | grep modified | sed 's/\(.*modified:\s*\)//'`
あるいは、もっと良い。
$ git ls-files --modified | xargs git add