LoginSignup
173
141

More than 5 years have passed since last update.

git commit --amendでaddし忘れたファイルを救済する

Posted at

一旦コミットしてからちょっとした修正を入れた場合に、この修正も元のコミットに含めてしまいたいことがある。
そんな時には、git commit --amendすれば一つ目のコミットに後からの修正もまとめることができる。

# aというファイルを追加し、一旦コミットする
$ git commit -m "add a file"

# その後、aに修正を入れる
$ git status
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:   a # <- aが修正されている

$ git add . # 変更をインデックスに登録
$ git commit --amend --no-edit # 登録されたインデックスを直前のコミットにまとめる 
$ git status
On branch master
nothing to commit, working directory clean

git commit --amend --no-editとすることで、エディタを開かずに修正することができる。

173
141
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
173
141