Git 合并多次提交
在合并分支的时候,希望将多次提交合并成一个,然后再 cherry-pick 到主分支。
合并分支
develop 分支做开发,可能会进行多次提交,但是在发布或者进行 PR 的时候,我们只希望看到一次提交。这个时候,我们需要进行 git rebase 之后进行合并。
# HEAD~3 表示将近三次提交都合并,如果是将 2 次合并则为 HEAD~2
git rebase -i HEAD~3
这个时候,看到的是一上对 COMMIT 信息的提示
pick 9ba5122 2017 年 8 月 2 日
pick c6da035 ~~
# Rebase 9b6bae1..c6da035 onto 9b6bae1 (2 commands)
#
# 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
第一列对应的是 rebase 具体的操作,其含义如下
| 命令 | 作用 |
|---|---|
| pick(p) | git 会应用这个补丁,以同样的提交信息(commit message)保存提交 |
| reword(r) | git 会应用这个补丁,但需要重新编辑提交信息 |
| edit(e) | git 会应用这个补丁,但会因为 amending 而终止 |
| squash(s) | git 会应用这个补丁,但会与之前的提交合并 |
| fixup(f) | git 会应用这个补丁,但会丢掉提交日志 |
| exec(x) | git 会在 shell 中运行这个命令 |
| drop(d) | git 会移除这次 COMMIT |
将第二个 pick c6da035 ~~~ 这一行修改成 squash c6da035 ~~~ ,使之与之前的提交合并。
保存之后可以看到下面的内容
This is a combination of 2 commits.
# This is the 1st commit message:
2017 年 8 月 2 日
删除无用配置,提高启动速度
1. 更新 zucchini-org
2. 增加 CHANGELOG 用来记录每次更新
3. 更新 plantuml 配置
FIXED Can't find plantuml-jar-path
4. 增加 parinfer 配置,用来优化 lisp 的编写速度
# This is the commit message #2:
~~
# Please enter the commit message for your changes. Lines starting
# with '#' will be ignored, and an empty message aborts the commit.
#
# Date: Tue Aug 1 10:24:44 2017 +0800
#
# interactive rebase in progress; onto 9b6bae1
# Last commands done (2 commands done):
"~/spacemacs/spacemacs.d/.git/COMMIT_EDITMSG" 36L, 1003C
修改成正确的 commit 信息之后,保存存并退出,可以看到下面的内容
$ git rebase -i HEAD~2
[detached HEAD 0238691] 2017 年 8 月 2 日
Date: Tue Aug 1 10:24:44 2017 +0800
5 files changed, 65 insertions(+), 34 deletions(-)
create mode 100644 CHANGELOG.org
rewrite local/custom.el (66%)
Successfully rebased and updated refs/heads/develop.
这个时候,就已经将我们这几次的更改都合并到一次中了。
cherry-pick 分支并更新
这个时候,就可以更新我们的代码了。
首先 git checkout master 分支, 然后更新我们的代码 git pull 。
然后将我们合并之后的 develop 分支的内容更新过来
git log -b develop
看到如下内容
commit 02386914b9e5ab13c23451a3463813bfdecb157a
Author: 语乱 <banshiliuli1990@sina.com>
Date: Tue Aug 1 10:24:44 2017 +0800
2017 年 8 月 2 日
删除无用配置,提高启动速度
1. 更新 zucchini-org
2. 增加 CHANGELOG 用来记录每次更新
3. 更新 plantuml 配置
FIXED Can't find plantuml-jar-path
4. 增加 parinfer 配置,用来优化 lisp 的编写速度
或者使用上次的操作的中的提示 [detached HEAD 0238691] 2017 年 8 月 2 日 其中的 0238691 就是我们需要
git cherry-pick 0238691
这样我们再推送到远程就可以实现合并更新了。
Git 合并多次提交的更多相关文章
- Git 合并多次 commit 、 删除某次 commit
Git 合并多次 commit 有时候在一个分支的多次意义相近的 commit,会把整个提交历史搞得很混乱,此时可以将一部分的 commit 合并为一个 commit,以美化整个 commit 历史, ...
- git合并多次commit提交
在开发项目工程中经常会遇到为了一个需求产生多次提交记录.有些是可以接受的,比如按照功能点不同进行的提交.但往往会存在这种,只为了一个小东西进行改动,比如多余文件的提交.书写不规范而不得不提交的情况.多 ...
- 使用Git-Rebase合并多次提交
在平时的软件开发中,我们每个team使用一个公共仓库(这里说的是Git仓库).每当有一个新的需求,我们会拉出一个特性分支,然后在这个特性分支上做开发以及提交个人的代码. 我有个习惯就是:为了确保代码的 ...
- git rebase 合并多次提交.
一.应用场景 为什么需要合并多个提交呢? 常常一个功能的开发,修修补补 commit 了 n 多次,带来的结果就是提交过多过杂,不够直观,究竟哪些提交是对应这个功能的呢?还有就是,如果我要将这个功能迁 ...
- 合并多次提交 commits 到 新分支
压缩多个Commit 当你提交代码进行代码审查时或者创建一次pull request (这在开源项目中经常发生),你的代码在被接受之前会被要求做一些变更.于是你进行了变更,并且直到下一次审查之前你没有 ...
- git 合并多次commit
如果当前分支提交了多次commit,无法merge到master上,就需要合并多出的几次commit 第一步 查看log: git log 第二步 git rebase -i HEAD~2 对最近的两 ...
- git 删除、合并多次commit提交记录
合并多次记录 1. git log找到要合并的记录的数量. 2. git rebase -i HEAD~5 将最上面一个的记录选为pack,下面记录都改为s. ================= 删除 ...
- git rebase的使用: 合并多次commit记录; rebase一个分支的起点
合并多次commit记录: good:https://blog.csdn.net/csdlwzy/article/details/83379546 使用 git log 命令查看提交历史: 想要合并前 ...
- 使用git rebase合并多次commit
使用git rebase合并多次commit 聊下 git rebase -i
随机推荐
- css实现简单的页面自适应宽度
1.css样式.lgn{ width:500px; height:20px;}.item_left_yd{ float: left; display: inline-block; width:240p ...
- Asp.net MVC中如何获取控制器的名称
如果在代码中 当前controller.action的获取RouteData.Route.GetRouteData(this.HttpContext).Values["controller& ...
- XTU 1236 Fraction
Fraction Accepted : 168 Submit : 1061 Time Limit : 1000 MS Memory Limit : 65536 KB Fraction Prob ...
- activiti 如何使用database前缀来区分activiti数据库和业务数据库
为什么80%的码农都做不了架构师?>>> 第一步是先集成好activiti,我使用的是5.22.0,使用springboot集成,pom文件如下: <parent> ...
- HTML5的5个的新特性
特性1:正则表达式 无须使用服务端的检测,使用浏览器的本地功能,就可以帮助你判断邮箱的格式,URL,电话,防止用户输入错误的信息,通过H5的pattern属性,很方便的整合这个功能. <inpu ...
- 蝶式套利(butterfly spread)
多头蝶式套利.预期市场价格趋于稳定,希望在这个价格区间内能获利,可选用多头蝶式套利,以较低的议定价格买进一个看涨期权,又以较高的议定价格买进一个看涨期权,同时又以介于上述2个议定价格之间的中等的议定价 ...
- Python--day61--Django项目配置相关
static文件查找:
- 使用vuex来管理数据
最近一直工作比较忙,博客已经鸽了好久了,趁着今天是周末,写点东西吧 使用vuex来管理数据 最近一直在用vue做项目,但是却从来没真正去用过vuex,因为一直感觉很复杂,其实真正去研究一下啊,就会发现 ...
- linux /proc 接口
无论何时一个硬件中断到达处理器, 一个内部的计数器递增, 提供了一个方法来检查设备 是否如希望地工作. 报告的中断显示在 /proc/interrupts. 下面的快照取自一个双处理 器 Pentiu ...
- 2018-2-13-手机1520-win8.1升级win10
title author date CreateTime categories 手机1520 win8.1升级win10 lindexi 2018-2-13 17:23:3 +0800 2018-2- ...