目的: 在同一branch上,将当前的commit与先前的commit合并
git rebase -i HEAD~2 (i的意思是:interactive,HEAD~2为在当前的前两个提交)
您还可以使用HEAD~4作为参数,它的工作原理是:“嘿,我们想要更改历史,因为在当前的历史后面有4个提交”。
1 pick 56a06ef change 1: remove one blank line
2 pick edbeab5 change 2: add log on MainActivity
3
4 # Rebase 23198ba..edbeab5 onto 23198ba (2 commands)
5 #
6 # Commands:
7 # p, pick <commit> = use commit
8 # r, reword <commit> = use commit, but edit the commit message
9 # e, edit <commit> = use commit, but stop for amending
10 # s, squash <commit> = use commit, but meld into previous commit
11 # f, fixup <commit> = like "squash", but discard this commit's log message
12 # x, exec <command> = run command (the rest of the line) using shell
13 # b, break = stop here (continue rebase later with 'git rebase --continue')
14 # d, drop <commit> = remove commit
15 # l, label <label> = label current HEAD with a name
16 # t, reset <label> = reset HEAD to a label
17 # m, merge [-C <commit> | -c <commit>] <label> [# <oneline>]
18 # . create a merge commit using the original merge commit's
19 # . message (or the oneline, if no original merge commit was
20 # . specified). Use -c <commit> to reword the commit message.
21 #
22 # These lines can be re-ordered; they are executed from top to bottom.
23 #
24 # If you remove a line here THAT COMMIT WILL BE LOST.
25 #
26 # However, if you remove everything, the rebase will be aborted.
27 #
28 # Note that empty commits are commented out
1 # This is a combination of 2 commits.
2 # This is the 1st commit message:
3
4 change 1: remove one blank line
5
6 # This is the commit message #2:
7
8 change 2: add log on MainActivity
9
10 # Please enter the commit message for your changes. Lines starting
11 # with '#' will be ignored, and an empty message aborts the commit.
12 #
13 # Date: Fri Apr 26 16:25:23 2019 +0800
14 #
15 # interactive rebase in progress; onto 23198ba
16 # Last commands done (2 commands done):
17 # pick 56a06ef change 1: remove one blank line
18 # squash edbeab5 change 2: add log on MainActivity
19 # No commands remaining.
20 # You are currently rebasing branch 'master' on '23198ba'.
21 #
22 # Changes to be committed:
23 # modified: app/src/main/java/com/example/jere/retrofit/MainActivity.java
24 #
1 # This is a combination of 2 commits.
2 # This is the 1st commit message:
3
4 change 1: remove one blank line && change 2: add log on MainActivity
5
6 # Please enter the commit message for your changes. Lines starting
7 # with '#' will be ignored, and an empty message aborts the commit.
8 #
9 # Date: Fri Apr 26 16:25:23 2019 +0800
10 #
11 # interactive rebase in progress; onto 23198ba
12 # Last commands done (2 commands done):
13 # pick 56a06ef change 1: remove one blank line
14 # squash edbeab5 change 2: add log on MainActivity
15 # No commands remaining.
16 # You are currently rebasing branch 'master' on '23198ba'.
17 #
18 # Changes to be committed:
19 # modified: app/src/main/java/com/example/jere/retrofit/MainActivity.java
20 #
refer:"https://medium.com/@igor_marques/combining-two-commits-84281f470ee8"