コミットを1つにまとめ、タイムスタンプを現在時刻にする。
コミットを1つにまとめる
$ git log --pretty=fuller commit 3bd88c199506179b48c9e2be3841be931b342ba4 (HEAD -> branchA) Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 17:29:48 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 17:29:48 2018 +0900 add commit3.txt commit 2c6b04c465cc49b80830fa1b7c51abf3dbd9b0fd Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 17:29:35 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 17:29:35 2018 +0900 add commit2.txt commit 60214c31c8ad7ab72d70d19bf676e9e6e9a442b6 Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 17:29:21 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 17:29:21 2018 +0900 add commit1.txt commit 3cb709bba00fcfddc07aa9427de8c399de88c1ea (origin/master, master) Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 01:05:38 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 01:05:38 2018 +0900 remove text
上3つのコミットを一つにまとめる。
$ git rebase -i HEAD~3
HEADから最新3つに対してrebaseすると以下の画面になる。
pick 60214c3 add commit1.txt pick 2c6b04c add commit2.txt pick 3bd88c1 add commit3.txt # Rebase 3cb709b..3bd88c1 onto 3cb709b (3 commands) # # Commands: # p, pick <commit> = use commit # r, reword <commit> = use commit, but edit the commit message # e, edit <commit> = use commit, but stop for amending # s, squash <commit> = use commit, but meld into previous commit # f, fixup <commit> = like "squash", but discard this commit's log message # x, exec <command> = run command (the rest of the line) using shell # d, drop <commit> = remove commit # l, label <label> = label current HEAD with a name # t, reset <label> = reset HEAD to a label # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>] # . create a merge commit using the original merge commit's # . message (or the oneline, if no original merge commit was # . specified). Use -c <commit> to reword the commit message. # # 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 60214c3 add commit1.txt squash 2c6b04c add commit2.txt squash 3bd88c1 add commit3.txt # Rebase 3cb709b..3bd88c1 onto 3cb709b (3 commands) # # Commands:
2c6b04cと3bd88c1のpickをsquashし、テキストを保存すると...
# This is a combination of 3 commits. # This is the 1st commit message: add commit1.txt # This is the commit message #1: add commit2.txt # This is the commit message #2: add commit3.txt # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Sun Jul 29 17:29:21 2018 +0900 # # interactive rebase in progress; onto 3cb709b # Last commands done (3 commands done): # squash 2c6b04c add commit2.txt # squash 3bd88c1 add commit3.txt # No commands remaining. # You are currently rebasing branch 'branchA' on '3cb709b'. # # Changes to be committed: # new file: commit1.txt # new file: commit2.txt # new file: commit3.txt
こんな画面が表示されるので、適当にコミットメッセージを書く。
combine 60214c3 2c6b04c 3bd88c1. # Please enter the commit message for your changes. Lines starting # with '#' will be ignored, and an empty message aborts the commit. # # Date: Sun Jul 29 17:29:21 2018 +0900 # # interactive rebase in progress; onto 3cb709b # Last commands done (3 commands done):
これで保存すると
$ git rebase -i HEAD~3 [detached HEAD a3f47e2] combine 60214c3 2c6b04c 3bd88c1. Date: Sun Jul 29 17:29:21 2018 +0900 3 files changed, 0 insertions(+), 0 deletions(-) create mode 100644 commit1.txt create mode 100644 commit2.txt create mode 100644 commit3.txt Successfully rebased and updated refs/heads/branchA.
こんな感じでrebase終了してupdateされる。
この時点でのログ
$ git log --pretty=fuller commit a3f47e27d52954915f63497d4b112054da98f241 (HEAD -> branchA) Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 17:29:21 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 17:34:18 2018 +0900 combine 60214c3 2c6b04c 3bd88c1. commit 3cb709bba00fcfddc07aa9427de8c399de88c1ea (origin/master, master) Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 01:05:38 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 01:05:38 2018 +0900 remove text
本来なら 3cb709bとa3f47e2の間に
3bd88c1 2c6b04c 60214c3
の三つがあるはずだけど、a3f47e2にまとめたので消えている。
コミットタイムスタンプを現在時刻に変更
この時点で最後にコミットしたものが以下
$ git log --pretty=fuller commit a3f47e27d52954915f63497d4b112054da98f241 (HEAD -> branchA) Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 17:29:21 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 17:34:18 2018 +0900 combine 60214c3 2c6b04c 3bd88c1.
こいつのCommitDateとAuthorDateを現在時刻にする。
$ git rebase HEAD~1 --ignore-date Current branch branchA is up to date, rebase forced. First, rewinding head to replay your work on top of it... Applying: combine 60214c3 2c6b04c 3bd88c1.
$ git rebase HEAD~1 --committer-date-is-author-date Current branch branchA is up to date, rebase forced. First, rewinding head to replay your work on top of it... Applying: combine 60214c3 2c6b04c 3bd88c1.
ログを確認
$ git log --pretty=fuller commit 50a2d8037f489e55074d46030bd742b0c9cdcbaa (HEAD -> branchA) Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 18:00:27 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 18:00:27 2018 +0900
新しいコミットなのでhash変わってるが、AuthoDateとCommitDateは現在時刻で合致した。
$ git log origin/branchA --pretty=fuller commit 50a2d8037f489e55074d46030bd742b0c9cdcbaa (HEAD -> branchA, origin/branchA) Author: HogeHoge <HogeHoge@HogeHoge.com> AuthorDate: Sun Jul 29 18:00:27 2018 +0900 Commit: HogeHoge <HogeHoge@HogeHoge.com> CommitDate: Sun Jul 29 18:00:27 2018 +0900 combine 60214c3 2c6b04c 3bd88c1.
push後のログもきちんと反映されてるー。
おわり。