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 ...
随机推荐
- [CF920G]List Of Integers
Description: \(t\)组询问,求第\(k\)个大于\(x\)且与\(p\)互质的数 Hint: \(x,k,p<=1e6,t<=30000\) Solution: 推出式子后 ...
- tcp timestamps
最近讨论到net.ipv4.tcp_timestamps这个系统配置是否能够开启,RFC文档上说道该值必须为单调递增,否则接受到的包可能会被丢掉 于是查看下tcp协议栈中是根据什么来生成这个times ...
- 第二章 flex处理二义性
大多数flex程序有二义性,相同的输入可能被多种模式匹配 flex通过下面2个规则来解决 匹配尽可能长的字符 如果2个模式都可以匹配, 匹配更早出现的那个模式 例子 "+" { r ...
- 机器学习笔记(2):线性回归-使用gluon
代码来自:https://zh.gluon.ai/chapter_supervised-learning/linear-regression-gluon.html from mxnet import ...
- Revit API创建标注NewTag
start ; ) { eId = item; } ...
- 阿里开源项目 druid 相关资料汇总
项目发起人访谈:http://www.iteye.com/magazines/90 github主页:https://github.com/alibaba/druid druid 项目,我想我能用很短 ...
- Linux 下安装 Mongodb
mongodb在linux下面的安装应该是很简单的,但是有一个小点需要注意,这也就是我为什么写这篇博客的原因. 首先到其官网上下载最新稳定版,解压到目录,如/usr/local/mongodb 在mo ...
- MDX 查询原型
本篇文章记录 SBS 中 MDX 查询原型,可以根据这些查询原型来解决实际项目中的问题. 1. 查询在 2004年1月2日 - 2004年3月1日之间购买过 Bikes 产品的用户. SELECT ( ...
- PRTG安装
1.去官网下载,记录下试用秘钥,然后执行安装 2. 3. 4.输入秘钥 5. 6.安装完成后自动转到如下页面,点击启动Guru 7. 8. 9. 10.输入prtgadmin,密码prtgadmin ...
- Java通过JNI调用C++程序
JNI是Java Native Interface的缩写,中文为JAVA本地调用.使用JNI可以很方便的用我们的Java程序调用C/C++程序.很多时候,某些功能用Java无法实现,比如说涉及到底层驱 ...