美文网首页
GIT之Rebase实用

GIT之Rebase实用

作者: 躺在家里干活 | 来源:发表于2019-08-28 18:12 被阅读0次

使用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 patch

Resolve 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实用

    使用Rebase合并不合理的Commit 查看需要合并的提交 git log --pretty=oneline 第...

  • 3.git高级篇总结

    阅读 Git 原理详解及实用指南 记录 高级 1:不喜欢merge的分叉,用rebase吧 介绍的是 rebase...

  • Git高级用法

    本文系作者扔物线之Git 原理详解及实用指南阅读笔记 一、rebase在新位置重新提交(merge后commit历...

  • git8~rebase

    2019.06.25 git rebase git stash git pull --rebase git sta...

  • 如何正确rebase

    git rebase -i origin/分支 合并冲突 git status git rebase --cont...

  • git整体学习

    基础 1. git ... 3. git rebase 第二种合并分支的方法是 git rebase。Rebase...

  • Git错误信息解决记录

    Git error: previous rebase directory .git/rebase-apply st...

  • Git使用教程

    拉取代码的正确步骤 git fetch git rebase git rebase --continue(遇到冲突...

  • Git 批量合并Commit或commit信息

    git rebase -i HEAD~3 git rebase -i [commitId-a] [commitId...

  • git merge conflict

    git pull --rebase编辑confilct的文件,修改完毕后git addgit rebase --c...

网友评论

      本文标题:GIT之Rebase实用

      本文链接:https://www.haomeiwen.com/subject/hlimectx.html