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 ...
随机推荐
- log4j.properties_配置
参考:http://blog.csdn.net/qq_30175203/article/details/52084127 参考:http://zengxiantao.iteye.com/blog/18 ...
- Unsupported major.minor version ,
一.错误现象: 当改变了jdk版本时,在编译java时,会遇到Unsupported major.minor version错误. 错误信息如下 : Unsupported major.minor ...
- Android-ContentProvider使用
Android-ContentProvider使用 一 建立ContentProviderserver端 1 建立一个继承自ContentProvider的类并重写接口方法(这里仅打一些log做代表) ...
- android:碎片的生命周期
和活动一样,碎片也有自己的生命周期,并且它和活动的生命周期实在是太像了,我相 信你很快就能学会,下面我们马上就来看一下. 4.3.1 碎片的状态和回调 还记得每个活动在其生命周期内可能会有哪几种 ...
- ldconfig , ldd 与 LD_LIBRARY_PATH 之间的关系
#注意事项 64位的linux机器上的默共享库的查找路径为:/lib64 /usr/lib64.实测发现不会搜索/lib /usr/lib.而且以上的两个目录没有什么so文件./usr/local/l ...
- nssm和AlwaysUp来包装exe文件为windows服务
最近遇到要把windows exe文件部署为service,因为原先开发为exe程序,现在有不想修改code改为service,但是部署必须是service服务, 所以我们需要一个包装器来包装exe为 ...
- [算法导论]插入排序 @ Python
class insertionsort(): def insertion_sort(self,Array): for i in range(1, len(Array)): key = Array[i] ...
- crontab不能执行sudo:抱歉,您必须拥有一个终端来执行 sudo
最近做一个可执行shell调度的需求,要求用户输入shell,然后后台定时调度运行.实现大致为:保存用户的输入,设定时间,crontab定时执行用户的输入.但这里涉及到一个安全问题,如何确定用户的输入 ...
- 解决IDEA授权报错
今天打开电脑,猛然发现IDEA授权失效,然后重新用账号密码登陆,发现被拒绝,各种百度百思不得其解,抱着试试的态度,点击了重置密码 https://account.jetbrains.com/forgo ...
- Django中使用Celery,定制应用程序中定义的shared_task未在定期任务管理页面的注册任务中显示
解决办法: 在项目 proj/proj/celery.py文件中,看到下面这行配置: celery_app.config_from_object('django.conf:settings', nam ...