0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

[備忘録シリーズ] gitで過去のcommitを修正する方法

Posted at

直前のcommitの場合

  1. git commit --amend -m “修正コメント”
  2. git rebase --continue
  3. push -f origin <target_branch>

2個以上前のcommitの場合

  1. git rebase -i HEAD~n (nは戻りたいcommitが直前のcommitから見て何番目かを入れる)
  2. 変更したいcommitを全てpickからeditへ変更し、保存
  3. git commit --amend -m “修正コメント”
  4. git rebase --continue
  5. HEADがeditしたcommitを古い順に移動するので、#3→#4を繰り返す
  6. git push origin <target_branch>(差分で問題があれば-fオプションを使う。気をつける)

ログの確認

  1. git log --onelineでHEADやcommit idの確認ができる
0
0
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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?