Git合并最近的commit
合并commit的做法一般用在pull request的时候,把开发同一功能时的所有琐碎的commit合并到一个(假装自己的代码是高质量代码(手动滑稽))。主要使用的命令是git rebase 或者git reset,这两个命令的区别可以看这里,一般推荐用git rebase,因为commit的历史能保存下来。
1. git rebase
首先用git log查看commit历史确定需要操作的commit,比如:
commit 0bca654809387dc226cfc4ff872f65601809f485
Author: CasiaFan <fanzongshaoxing@gmail.com>
Date: Wed Aug 16 13:13:12 2017 +0800
fix typo
commit b5bf9998e40dc165d7e3055bae47172de11225d4
Author: CasiaFan <fanzongshaoxing@gmail.com>
Date: Wed Aug 16 10:02:30 2017 +0800
add random vertical flip during image preprocessing
commit 70a4958184106b9ce848da34be34bdf0dbf36450
Author: CasiaFan <fanzongshaoxing@gmail.com>
Date: Wed Aug 16 09:58:55 2017 +0800
step by step running
commit d68608c2dbd41a1b89363f4b743bc5464b6749be
Author: CasiaFan <fanzongshaoxing@gmail.com>
Date: Mon Aug 14 15:52:47 2017 +0800
modify description
如果需要操作最近4个commit:
git rebase -i HEAD~4 # 操作对象为从倒数第4个commit开始到当前的commit
# git rebase -i d68608c2dbd41a1b89363f4b743bc5464b6749be # 倒数第4个commit 的id
然后会跳出编辑页面像这样:
pick d68608c modify description
pick 70a4958 step by step running
pick b5bf999 add random vertical flip during image preprocessing
pick 0bca654 fix typo
# Rebase 529bf46..0bca654 onto 529bf46 (4 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
#
# 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
把需要保留的commit之前保留pick,需要合并的前面改成squash,编辑保存退出以后输入新的commit message,最后保存退出。
# This is a combination of 6 commits.
add random vertical flip for image preprocessing # 合并后的commit
# The first commit's message is:
test
# This is the 2nd commit message:
object detection api usage step
# This is the 3rd commit message:
modify description
# This is the 4th commit message:
step by step running
# This is the 5th commit message:
add random vertical flip during image preprocessing
# This is the 6th commit message:
fix typo
这个时候再git log的日志如下:
commit 7f774d88eb6884c97c8b3c05a9268afa581d5b57
Author: Unknown <fanzongshaoxing@gmail.com>
Date: Mon Aug 14 15:45:29 2017 +0800
add random vertical flip for image preprocessing
test
object detection api usage step
modify description
step by step running
add random vertical flip during image preprocessing
fix typo
如果修改了一半不想合并了就用git rebase --abort
删除。
git reset
git reset --soft "HEAD~4"
git commit --amend
或者
git reset --hard HEAD~4 # 将branch状态切到到4个commit之前
git merge --squash HEAD@{1} # 将当前commit(此时为倒数第四个)之后的commit都合并
git commit # commit squashed changes
参考
https://stackoverflow.com/questions/5189560/squash-my-last-x-commits-together-using-git
https://stackoverflow.com/questions/2563632/how-can-i-merge-two-commits-into-one
http://zerodie.github.io/blog/2012/01/19/git-rebase-i/
Git合并最近的commit的更多相关文章
- (转)git合并多个commit
原文地址:http://platinhom.github.io/2016/01/02/git-combine_commit/ 有时commit多了看着会不爽.所以想合并掉一些commit. 这里是最简 ...
- Git合并多个Commit
当前有四个commit,现在要将四个commit合并为一个,可以使用git rebase -i HEAD~{这里是要合并的commit数量} 如 git rebase -i HEAD~4 ,即为合并最 ...
- Git合并一次commit到指定分支
1 在当前分支,查看要合并的分支版本号 git log 需要合并的commit版本号 16b7df3aa1e64e00554a8a3c871e59db8cd87b16 2 切换到 指定分支 git c ...
- git 合并多个commit
1,查看提交历史,git log 首先你要知道自己想合并的是哪几个提交,可以使用git log命令来查看提交历史,假如最近4条历史如下: commit 3ca6ec340edc66df13423f36 ...
- git 合并某个提交commit到指定的分支上
https://blog.csdn.net/anhenzhufeng/article/details/77962943 git checkout master git cherry-pick 62ec ...
- IDEA git 合并多个commit
当前三个commit,demo1,demo2,demo3 选择demo1右键 选择action 跟着指示操作,最后合并 时间线: Log 框时间线:是从上到下,越来越早. 弹出框时间线:是从上到下,越 ...
- Git自动化合并多个Commit
目录 git rebase逻辑 git editor的修改 处理git-rebase-todo文件 Python实现 当我们有多个commit或者从开源处拿到多个commit时,想合成一个commit ...
- git合并分支上指定的commit
merge 能够胜任平常大部分的合并需求.但也会遇到某些特殊的情况,例如正在开发一个新的功能,线上说有一个紧急的bug要修复.bug修好了但并不像把仍在开发的新功能代码也提交到线上去.这时候也许想要一 ...
- git将多个commit合并成一个
1. 查看提交历史(最近10个) git log - 2. 回到前面第十个commit,且将后面九个commit提交的内容状态改为未提交 git reset commitID(第十个commit的ID ...
随机推荐
- 20172302 《Java软件结构与数据结构》第七周学习总结
2018年学习总结博客总目录:第一周 第二周 第三周 第四周 第五周 第六周 第七周 教材学习内容总结 第11章 二叉查找树 1.二叉查找树是一种含有附加属性的二叉树,该属性即其左孩子小于父节点,而父 ...
- 转:甲骨文发布大数据解决方案 含最新版NoSQL数据库
原文出处: http://www.searchdatabase.com.cn/showcontent_88247.htm 以下是部分节选: 最新发布的大数据创新成果包括: Oracle Big Dat ...
- PS文字生成头像
链接: 教你用PS把文字拼成肖像.... 28个文字组成的肖像画欣赏
- Spark MLlib 之 aggregate和treeAggregate从原理到应用
在阅读spark mllib源码的时候,发现一个出镜率很高的函数--aggregate和treeAggregate,比如matrix.columnSimilarities()中.为了好好理解这两个方法 ...
- Android开发中遇到的问题(一)——Android模拟器端口被占用问题的解决办法
一.问题描述 今天在Eclipse中运行Android项目时遇到"The connection to adb is down, and a severe error has occured& ...
- VS2010链接TFS遇见错误:TF204017,没有访问工作区域,需要一个或者多个必须权限
最近刚刚搭建好服务器,然后准备将VSS源代码迁移到TFS源代码管理服务器上面.在我本机先用的服务器帐号来上传初始化源代码数据库,然后我又用自己的帐号进行迁出代码的时候发生的异常. 造成上述错误,主要是 ...
- Tomcat服务器配置https双向认证(使用keytool生成证书)
一,HTTPS原理 1,HTTP.HTTPS.SSL.TLS介绍与相互关系 (1)HTTP:平时浏览网页时候使用的一种协议.HTTP协议传输的数据都是未加密的(明文),因此使用HTTP协议传输隐私 ...
- caffe中的fine-tuning
caffe finetune两种修改网络结构prototxt方法 第一种方法:将原来的prototxt中所有的fc8改为fc8-re.(若希望修改层的学习速度比其他层更快一点,可以将lr_mult改为 ...
- Andorid之官方导航栏Toobar
在前面学习使用ActionBar的时候,我们就发现ActionBar中有些方法被标记为过时了,原来在android5.0之后,google推出了一个新的导航工具栏,官方将其定义为:A standard ...
- 这些年我在技术路上做过最虚伪愚蠢的事情,就是在CSDN上刷屏赚分
现在似乎Github成了所谓技术人士的新宠,之前是博客,更早则是论坛. CSDN是众多技术论坛里比较突出的一个,人多高手也多,很多问题都能得到满意的回答. 谁都希望自己卓尔不群,我也不例外,我也想像那 ...