Git rebase操作
来源:互联网 发布:java设计模式书籍知乎 编辑:程序博客网 时间:2024/05/21 22:52
1、git rebae -I
说明:对单个分支做rebase,将当前分支未push到远程服务器的提交做整理,就像把这部分提交拿出来逐条整理一遍,可以修改提交的文件,做增补提交,可以修改提交注释,可以合并到上一条提交,可以删除某条提交等。
图示:
E---F---G 分支A
/
A---B---C---D origin/分支A
从图示上看到分支A在本地有E、F、G 3条提交没有push到远程服务器,现在在分支A上用git rebase -i就可以对这3条提交做整理
命令:
1.1git rebase -I
弹出编辑器,内容如下
pickE注释
pickF注释
pickG注释
#RebaseD..Gonto D
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commitmessage
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld intoprevious commit
# f, fixup = like "squash", butdiscard this commit's log message
# x, exec = run command (the rest of the line)using shell
#
# These lines can bere-ordered; they are executed from top to botto
#
# If you remove aline here THAT COMMIT WILL BE LOST.
#
# However, if youremove everything, the rebase will be aborted.
#
# Note that emptycommits are commented out
说明:
pickE注释
pickF注释
pickG注释
这部分的pick是可以编辑修改的,如编辑内容所示,可以改成pick、reword、edit、squash、fixup、exec
pick:不做任何修改;
reword:只修改提交注释信息;
edit:修改提交的文件,做增补提交;
squash:将该条提交合并到上一条提交,提交注释也一并合并;
fixup:将该条提交合并到上一条提交,废弃该条提交的注释;
如果删除了某行记录,比如删除“pick G 注释”,这条提交也会被删除。
1.2编辑完成后,保存退出;
1.3如果有edit的操作,git会新建一个rebase分支,将提交reset到edit的这条记录,做增补提交之后,再用 git rebase --continue ,git继续执行rebase,成功之后回到分支A,
如果有reword和squash的操作,会弹出编辑提交注释,修改后保存退出,git自动继续执行rebase。
其他的命令,git rebase会自动执行。
2、git rebase分支A分支B
说明:将分支B变基到分支A的最新版本上,如果是分支B留空则是将当前分支变基到分支A的最新版本上
图示:
E---F---G 分支B
/
A---B---C---D---H---I---J 分支A
命令:git rebase分支A分支B 或者在分支B上用 git rebase 分支A 结果一样
结果:
E'---F'---G' 分支B
/
A---B---C---D---H---I---J 分支A
3、git rebase --onto分支A 分支B分支C
说明:这个操作是想将分支C变基到分支A的最新版本上,而分支C和分支A是通过分支B间接关联起来的。
图示:
K---L---M 分支C
/
E---F---G 分支B
/
A---B---C---D---H---I---J 分支A
命令:git rebase --onto分支A 分支B分支C
结果:
E---F---G 分支B
/ K'---L'---M '分支C
/ /
A---B---C---D---H---I---J 分支A
分支C和分支B的关系去掉了,但是他们之间共同修改过的文件,分支B上的修改的也会加到分支C上。
注:如果是跳过分支B,用命令git rebase --onto 分支A 分支C会出现这个错误
First,rewinding head to replay your work on top of it...
- Git rebase操作
- git rebase操作
- git操作之git rebase
- Git 操作之rebase、squash
- 【Git入门之十】Rebase操作
- Git Rebase 操作的分析与整理
- git- rebase
- git rebase
- git rebase
- git rebase
- git rebase
- git rebase
- git rebase
- git rebase
- git rebase
- Git rebase
- Git Rebase
- git rebase
- Java Calendar获取年、月、日、时间
- 一些不错的ios学习站点
- 布隆过滤器 bloom filter
- Delphi中常用字符串处理函数
- io exception:The Network Adapter could not establish the connection解决办法
- Git rebase操作
- navicat for myql 注册码
- DialogBar使用注意事项
- 恭喜自己考上东南大学博士,努力啊,争取早日有所成就!
- Java 泛型学习(二)泛型集合应用:实现对Map的迭代
- Python内建函数(H)
- java获得windows系统当前时间与时间不符合
- Delphi中,indy控件实现收发邮件的几点学习记录( 可以考虑加入多线程,用多个邮箱做一个邮箱群发器) 转
- android之照相、相册裁剪功能的实现过程