git之将两个请求合并为一个请求

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), 推送完成, 如下所以,完成将两个提交合并为一个。

posted @ 2020-11-05 23:24  King-DA  阅读(2210)  评论(0编辑  收藏  举报