使用Rebase合并不合理的Commit

查看需要合并的提交

git log --pretty=oneline

a53ddc61dad65c74cf0b5e6026393a76a475e8e8 (HEAD -> bet-activiey-rebase) 修改ignore
c3fc493086fc2afe437a1eb683fefd613df8f147 (origin/bet-activity, bet-activity) 处理orderNo为""的情况
2c058020d9cde54af67df66fe866fcbcff4b5ec9 处理腾讯返回时间
7e8d555c22c897647fb1afd93fe3a57f04af0f65 修改时间解析方式
6a2de6f6dca496297a8d40cbd2e9674146f93945 更换时间计算方式
2c504089f7c63c9c1e0459e2b2b3a5bbf27c6a46 checkstyle
3e542678da40cd2961617c3213bfd7f3744bc604 处理支付时间的问题
d996da46eb01f3c139b3e201d8b6d07b4d37780d 处理重复的订单号问题
d79017c1f7406f6f14e35ce609827314465e6946 新增日志,查看付款状态
b034f66dcc8f1db3d01419eae4cc465cee4c9761 优化代码
614bc7eb10853988f8f0def3d33caa183d08da94 修改解析腾讯返回returnMsg不为必须值
62714e9f63380885d1fcf9ea5bf0e3456528b015 修改路径
a96972e443979e7c12a28e50f22feef356159974 修改路径
7aa73908e4053d75144dda3ffd1db991e697173f 修改路径
bc3bc15e56245f0793c7bbe3cb18d9f0908f0967 修改路径
4d142e9dabc8daa6eb6f051fc6473e59dfe394b1 checkstyle
579ed59894d2848357d0911ddb29971eef4888a5 checkstyle
6e5a444309a1fab4a65fc242a2f343ba7bc78891 重新生成jooq
3b5e01c61b3f3c8a6637b6dc9d88aa99e4991bde 修复大小写问题:删除之前存在的文件
58d9c7b912c6aa0a9be0c3e431a7d80bce9aa7b8 修复大小写问题
1fb03d8fdadbd52773a3f2cb1f7ddeba7c7a9acb 修改GIT忽略文件名大小写
5a9d94e5e401c97d7f23d8826716f03aab425222 微信支付完善,以及企业付款查询接口
f1d85ef4d3d6c47663d847b67cae5455eaf4cf20 (origin/develop, origin/HEAD, develop) Revert

第一步,我们可以一直合并到f1d85ef4d3d6c47663d847b67cae5455eaf4cf20

我们首先合并前6个,到3e542678da40cd2961617c3213bfd7f3744bc604

git rebase -i 3e5426

Available options are-v, --verbose         display a diffstat of what changed upstream-q, --quiet           be quiet. implies --no-stat
pick 2c50408 checkstyle
pick 6a2de6f 更换时间计算方式
pick 7e8d555 修改时间解析方式
pick 2c05802 处理腾讯返回时间
pick c3fc493 处理orderNo为""的情况
pick a53ddc6 修改ignore# Rebase 3e54267..a53ddc6 onto 3e54267 (6 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

确定之后使用wq保存,之后如果需要修改commit message会弹出修改的页面。

常用命令:

操作 含义
pick 使用当前commit
reword 使用当前commit,但是要修改commit message
edit 使用当前commit,rebase时会暂停,允许你修改这个commit
squash 使用当前commit,会将当前commit与上一个commit合并
fixup 效果和squash一样,但是不会保持commit message
drop 放弃当前commit

查看合并后的情况

b9e4e4edd63e86344194dc4809f7e42e0c708f2b (HEAD -> bet-activiey-rebase) 更换时间介些方式,checkstyle
3e542678da40cd2961617c3213bfd7f3744bc604 处理支付时间的问题
d996da46eb01f3c139b3e201d8b6d07b4d37780d 处理重复的订单号问题
d79017c1f7406f6f14e35ce609827314465e6946 新增日志,查看付款状态
b034f66dcc8f1db3d01419eae4cc465cee4c9761 优化代码
614bc7eb10853988f8f0def3d33caa183d08da94 修改解析腾讯返回returnMsg不为必须值
62714e9f63380885d1fcf9ea5bf0e3456528b015 修改路径
a96972e443979e7c12a28e50f22feef356159974 修改路径
7aa73908e4053d75144dda3ffd1db991e697173f 修改路径
bc3bc15e56245f0793c7bbe3cb18d9f0908f0967 修改路径
4d142e9dabc8daa6eb6f051fc6473e59dfe394b1 checkstyle
579ed59894d2848357d0911ddb29971eef4888a5 checkstyle
6e5a444309a1fab4a65fc242a2f343ba7bc78891 重新生成jooq
3b5e01c61b3f3c8a6637b6dc9d88aa99e4991bde 修复大小写问题:删除之前存在的文件
58d9c7b912c6aa0a9be0c3e431a7d80bce9aa7b8 修复大小写问题
1fb03d8fdadbd52773a3f2cb1f7ddeba7c7a9acb 修改GIT忽略文件名大小写
5a9d94e5e401c97d7f23d8826716f03aab425222 微信支付完善,以及企业付款查询接口
f1d85ef4d3d6c47663d847b67cae5455eaf4cf20 (origin/develop, origin/HEAD, develop)

可以看到前几个合并到了第一个里面

  1. 把中间的几个相同描述的提交进行合并
d79017c1f7406f6f14e35ce609827314465e6946 新增日志,查看付款状态
b034f66dcc8f1db3d01419eae4cc465cee4c9761 优化代码
614bc7eb10853988f8f0def3d33caa183d08da94 修改解析腾讯返回returnMsg不为必须值
62714e9f63380885d1fcf9ea5bf0e3456528b015 修改路径
a96972e443979e7c12a28e50f22feef356159974 修改路径
7aa73908e4053d75144dda3ffd1db991e697173f 修改路径
bc3bc15e56245f0793c7bbe3cb18d9f0908f0967 修改路径
4d142e9dabc8daa6eb6f051fc6473e59dfe394b1 checkstyle
579ed59894d2848357d0911ddb29971eef4888a5 checkstyle

git rebase -i 6e5a444309a1fab4a65fc242a2f343ba7bc78891

我们这次要保留最初的几个提交,然后合并上述的提交,编辑后的文件

r 579ed59 checkstyle
s 4d142e9 checkstyle
s bc3bc15 修改路径
s 7aa7390 修改路径
s a96972e 修改路径
s 62714e9 修改路径
s 614bc7e 修改解析腾讯返回returnMsg不为必须值
s b034f66 优化代码
s d79017c 新增日志,查看付款状态
pick d996da4 处理重复的订单号问题
pick 3e54267 处理支付时间的问题
pick b9e4e4e 更换时间介些方式,checkstyle

如果文件中使用的是squash方式合并代码,会出现合并message的操作

# This is a combination of 9 commits.
# This is the 1st commit message:调整路径,优化代码# This is the commit message #1:checkstyle# This is the commit message #2:修改路径# This is the commit message #3:修改路径# This is the commit message #4:修改路径# This is the commit message #5:修改路径# This is the commit message #6:修改解析腾讯返回returnMsg不为必须值# This is the commit message #7:优化代码# This is the commit message #8:新增日志,查看付款状态# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date:      Mon Jul 15 16:06:28 2019 +0800
#
# interactive rebase in progress; onto 6e5a444
# Last commands done (9 commands done):

这里要使用 #操作,来表示忽略某个commit message

修改之后提交,打开log

58a752e06fb164960448d3e1383cd1f7c35f1762 (HEAD -> bet-activiey-rebase) 更换时间介些方式,checkstyle
54bac4f74809688b2a2ccae91aa4dfb68def5b17 处理支付时间的问题
1c873bbf933df5f42268e85e5dae914aa747c064 处理重复的订单号问题
d1c0883ed015a2655859564cc9ab69bf77a292ad 调整路径,优化代码
6e5a444309a1fab4a65fc242a2f343ba7bc78891 重新生成jooq
3b5e01c61b3f3c8a6637b6dc9d88aa99e4991bde 修复大小写问题:删除之前存在的文件
58d9c7b912c6aa0a9be0c3e431a7d80bce9aa7b8 修复大小写问题
1fb03d8fdadbd52773a3f2cb1f7ddeba7c7a9acb 修改GIT忽略文件名大小写
5a9d94e5e401c97d7f23d8826716f03aab425222 微信支付完善,以及企业付款查询接口
f1d85ef4d3d6c47663d847b67cae5455eaf4cf20 (origin/develop, origin/HEAD, develop) Revert "添加获取腾讯通用accessToken"

和一开始的相比,清爽很多吧

另外一种方式合并 54bac4 和 1c873b

git rebase --onto d1c0883 54bac4f bet-activiey-rebase

First, rewinding head to replay your work on top of it...
Applying: 更换时间介些方式,checkstyle
Using index info to reconstruct a base tree...
M   src/main/java/com/xingren/services/weixin/facade/WeixinPayFacade.java
Falling back to patching base and 3-way merge...
Auto-merging src/main/java/com/xingren/services/weixin/facade/WeixinPayFacade.java
CONFLICT (content): Merge conflict in src/main/java/com/xingren/services/weixin/facade/WeixinPayFacade.java
error: Failed to merge in the changes.
Patch failed at 0001 更换时间介些方式,checkstyle
Use 'git am --show-current-patch' to see the failed patchResolve all conflicts manually, mark them as resolved with
"git add/rm <conflicted_files>", then run "git rebase --continue".
You can instead skip this commit: run "git rebase --skip".
To abort and get back to the state before "git rebase", run "git rebase --abort".

解决冲突后**git add <filename>**

$ git rebase --continue
Applying: 更换时间介些方式,checkstyle

git rebase —onto的作用不只这些,具体的可以看看帮助文档,有机会用到的话会写博客出来

注意:

  1. 如果有冲突需要解决冲突并使用git add <filename>命令把修改后的文件加入暂存区,然后使用git rebase --continue继续进行rebase
  2. 如果碰到问题可以使用git rebase --abort放弃当前rebase

特别声明:

遇事不决,请使用git rebase --help

我的个人博客,有空来坐坐

GIT之Rebase的使用相关推荐

  1. Git 分支 - rebase 变基

    变基 在 Git 中整合来自不同分支的修改主要有两种方法:merge 以及 rebase. 在本节中我们将学习什么是"变基",怎样使用"变基",并将展示该操作的 ...

  2. git pull --rebase 做了什么? 以及 Cannot rebase: You have unstaged changes 解决办法

    前些天发现了一个巨牛的人工智能学习网站,通俗易懂,风趣幽默,忍不住分享一下给大家.点击跳转到教程. 最近刚学 git rebase,觉得很牛逼的样子,  结果今天就被打脸了. git pull --r ...

  3. git使用—rebase还是merge

    转载自:https://segmentfault.com/q/1010000007704573/ 我猜现实中的情况是这样的: 使用 git 的人群中,不会用 rebase(哪怕是基础功能的)的至少一半 ...

  4. git pull rebase

    微软MVP写的, 条例很清楚 https://www.cnblogs.com/wangiqngpei557/p/6056624.html 官方教材的翻译, 还是有点费解 https://git-scm ...

  5. 为什么要使用git pull --rebase?

    1.git pull git pull = git fetch + git merge FETCH_HEAD git pull --rebase = git fetch + git rebase FE ...

  6. 【Git】git pull和git pull --rebase的使用

    git pull = git fetch + git merge git pull --rebase = git fetch + git rebase 现在来看看git merge和git rebas ...

  7. git 交互式rebase

    交互式的rebase的场景在分支开发时特别有用, 可以减少没有必要的提交 git rebase -i -i 参数表示互动 interactive,这时 git 会使用你设定的编辑器,让你对 git 历 ...

  8. git pull origin master与git pull --rebase origin master的区别

    建议:最好看一遍廖雪峰的git教程,看完时间差不多就两个小时,git相关的知识写的很清楚,看完整个人都豁然开朗,很多git的问题都想通了. 区别: git pull=git fetch + git m ...

  9. git pull --rebase 出错处理

    有时候,我们从仓库clone代码的时候,在本地会改一些配置文件,但又不能push到master主干上,怎么办? 1.git add (单个文件) 一个一个提交 2.git commit -m &quo ...

  10. git pull --rebase PK git pull

    在使用git的日常开发过程中,经常遇到如下情况: 1.某个时间你通过git clone/git fetch拉取了远程仓库代码到本地仓库 2.开始本地调试并开发某个功能,经过几天的奋斗,终于功能调试好了 ...

最新文章

  1. sqlserver 指数_指数基金的分类有哪些?
  2. 通过Matlab发送邮件要注意的问题
  3. 精通android布局,Android精通:View与ViewGroup,LinearLayout线性布局,RelativeLayout相对布局,ListView列表组件...
  4. python如何记录运行时间_Python如何测量脚本运行时间
  5. Java微服务篇1——SpringBoot
  6. android textview 背景图片,Android—TextView 背景颜色与背景图片设置
  7. mac服务器证书失效,Mac OS X Server:软件更新证书过期
  8. python函数做n_【python】定义函数、参数、递归(n!)
  9. 【Python-2.7】如何判断对象是否为可迭代?
  10. 使用hiredis接口(Synchronous API)编写redis客户端
  11. 华为云计算hcip证书有效期_华为认证云计算 V4.0认证
  12. vscode如何快捷键一键生成vue模板
  13. FTP-文件传输协议
  14. 《东周列国志》第四十五回 晋襄公墨缞败秦 先元帅免胄殉翟
  15. Linux内核之进程管理
  16. 7款英文语法检查工具推荐
  17. html组态插件_组态 web组态 组态插件 编辑器 工业组态 物联网组态 组态编辑器...
  18. power oj 2866青春猪头少年不做怀梦美少女的梦(寻找母串中有多少个子串)
  19. 项目1在线交流平台-7.构建安全高效的企业服务-2.使用Security自定义社区网页认证与授权
  20. 科研新手该如何找到合适的文献?| 开启科研之路(王威教授)

热门文章

  1. OpenCV学习Rosenfeld细化算法
  2. 对微软在隐私策略上的让步,EFF表示欢迎
  3. 转:GRE_那些不讨人爱的4字母单词
  4. .Net framework3.5装不上解决之道错误代码 0x800F0906、0x800F081F
  5. kotlin 属性重载
  6. 如何让计算机按图片的顺序打印,如何将电脑中的几张图片打印在一张纸上
  7. 文件名字超出计算机无法删除,win7文件名太长无法移动和删除的解决方法
  8. 1. 从WordPress搬家到网易博客!
  9. 标准c语言程序文件名后缀为,CCS_C语言编程
  10. 关于心理的二十五种倾向(查理·芒格)-3