LoginSignup
5
2

More than 5 years have passed since last update.

git で過去のコミットをまとめる。

Last updated at Posted at 2018-06-10

何回やっても不安になるので備忘録的に記載

git logでこんな感じになっていて、すべてを 開発中1 にまとめたい場合

commit e9c336ee9898f52235a6b080460ab7f3c3d9e1ae
Author: hogehoge<hoge@hage>
Date:   Sun Jun 10 09:01:21 2018 +0900

    開発中3

commit a778f5a235x639a7ac0c159296e3edcb5b1737c3
Author: hogehoge<hoge@hage>
Date:   Sun Jun 10 08:32:59 2018 +0900

    開発中2

commit 012627a2552a8a23e650aca5e8a5323536b64a3c
Author: hogehoge<hoge@hage>
Date:   Sat Jun 9 05:13:31 2018 +0900

    開発中1

commit 22698f5a235a6cb56c3ac60a2cdbaccc045a8537
Author: hogehoge<hoge@hage>
Date:   Fri Jun 8 21:00:05 2018 +0900

   開発はじまり

一番下の「開発はじまり」のコミットポイントを指定して git rebase を実行する。

git rebase -i 22698f5a235a6cb56c3ac60a2cdbaccc045a8537

実行すると下記の通りの確認画面が立ち上がる。

pick 012627a 開発中1
pick a778f5a 開発中2
pick e9c336e 開発中3

# Rebase 22698f..e9c336e onto 22698f (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

マージさせたいものを squash で指定する。

pick 012627a 開発中1
squash a778f5a 開発中2
squash e9c336e 開発中3

保存して閉じるとコメント入力を求められるので、

# Merage
コミットをマージする。

といった感じで記載する。

結果下記のように

commit 012627a2552a54a03d2c31a5e8f5723536a64a3c
Author: hogehoge<hoge@hage>
Date:   Sat Jun 9 05:13:31 2018 +0900

    コミットをマージする。

commit 22698f5a235a6cb56c3ac60a2cdbaccc045a8537
Author: hogehoge<hoge@hage>
Date:   Fri Jun 8 21:00:05 2018 +0900

    開発はじまり

とまとめられる

git push -f origin ブランチ名

で強制的にgitリモートに持っていける。
共同開発時は超注意

5
2
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
5
2