1.為什么需要將兩次提交的請求合並為一個請求進行提交?
1.審核代碼時候,更加方便一些。
2.多次的提交可能只是為了修復一個bug。
3.更加方便別人為你審閱代碼信息。
2.怎么才能將兩次請求合並為一個請求進行提交?
1.使用git命令,可以看到如下的文本信息。
git rebase -i HEAD~2
解釋:該命令可以將你兩次提交的請求在以文本的形式進行展示
如果數字2換成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
3.將第二行的pick 修改成s或者f。如果修改為s,那么你之前進行的提交不會消失,如果是f的話,那么你之前進行的提交信息,都會消失。
1 pick 56a06ef change 1: remove one blank line 2 s 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
注意:這里的文本編輯操作不做詳細描述,不會的可以查看linux下的基本命令。
4.保存退出后,push代碼:git push -f (注意:因為時rebase操作,所以要加-f, 強制push), 推送完成, 如下所以,完成將兩個提交合並為一個。