Git コマンドをしょっちゅう忘れたり、調べたりしているので、いい加減ブログにしておく。
コミットをまとめる
rebase -i
で良い
失敗して、変なのコミットしたので、直近の2つのコミットをまとめたい。
$ git rebase -i HEAD~2
エディタがたちがある。
pick e8ccc98 Returning body only
pick 5c02485 fix slow FileUpload
# Rebase b4bf38e..5c02485 onto b4bf38e (2 commands)
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# These lines can be re-ordered; they are executed from top to bottom.
#
# If you remove a line here THAT COMMIT WILL BE LOST.
#
# However, if you remove everything, the rebase will be aborted.
#
# Note that empty commits are commented out
まとめたいコミットは、pick
を s
に変更する。 結果は、git log
で確認するといよい。
コミットメッセージを変更したい
git commit --amend
で良い。ちなみに、直前ではなく、ちょっと前のコミットを修正したい場合はgit rebase -i HEAD~xx
を使って、特定のコミットをedit
にする詳しくはこちら
GitHub のブランチを削除する
git push origin :branch
で良い
git push origin branch
は
git origin branch(local):branch(remote)
の意味なので、空がプッシュされる。
$ git push origin :fix/slowbackend
Enter passphrase for key '/Users/ushio/.ssh/id_rsa':
To github.com:Azure-Samples/customer-car-reviews.git
- [deleted] fix/slowbackend