LoginSignup
0
3

More than 5 years have passed since last update.

`git rebase -i` でコミットをまとめる心意気

Posted at

なかなか覚えられないので…。
汚いログが許されるのは小学生まで。

バリバリfeature/Aの実装をするぞ!

date > date.md ; git commit -am "WIP: feature/A"
date > date.md ; git commit -am "WIP: feature/A hoge"
date > date.md ; git commit -am "WIP: feature/A moge"

コミットログ

git log --oneline
aa85fbe WIP: feature/A moge
db0645b WIP: feature/A hoge
464b054 WIP: feature/A
37c47c6 作業前のコミット

これをまとめたい

「作業前のコミット」以後をまとめたいとする。
rebaseには「作業前のコミット」のhashを指定する。

git rebase -i 37c47c6
pick 464b054 WIP: feature/A
pick db0645b WIP: feature/A hoge
pick aa85fbe WIP: feature/A moge

# Rebase 37c47c6..aa85fbe onto 37c47c6 (3 command(s))
#
# 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

上から古い順にcommitが並ぶ。
一番古いcommitに全部まとめます。

pick 464b054 WIP: feature/A
s db0645b WIP: feature/A hoge
s aa85fbe WIP: feature/A moge

一番古いcommitにまとめたいので sにします。
meld into previous commitという英語はわかりやすい。

コミットログの編集になるので、以下のようにする。

feature/A

まとまった。

commit b0e4523f24f48b84eccf41f4f024cf723a202a42
Author: kaibadash
Date:   Thu Mar 23 14:52:40 2017 +0900

    feature/A
0
3
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
3