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
随机推荐
- 严重: Servlet.service() for servlet [jsp] threw exception java.lang.NullPointerException
五月 04, 2018 11:53:24 上午 org.apache.catalina.core.ApplicationDispatcher invoke 严重: Servlet.service() ...
- 2019-9-2-git-需要知道的1000个问题
title author date CreateTime categories git 需要知道的1000个问题 lindexi 2019-09-02 10:12:31 +0800 2018-2-13 ...
- CentOS7增加或修改SSH端口号
https://blog.csdn.net/ausboyue/article/details/53691953 前言:开启某服务或软件的端口,要从该服务或软件监听的端口(多以修改配置文件为主),SeL ...
- 反思K-S指标(KPMG大数据挖掘)
评估信用评级模型,反思K-S指标 2015-12-05 KPMG大数据团队 KPMG大数据挖掘 “信用评级”的概念听起来可以十分直截了当.比如一天早上你接到电话,有个熟人跟你借钱,而你将在半睡半醒间迅 ...
- [转载] Solaris命令使用
摘自: http://www.jb51.net/os/Solaris/18533.html ★6. rm 删除文件 命令格式: rm [-r] filename (filename 可为档名,或档 ...
- H3C 配置高级ACL
- 用adblock过滤页面上固定位置的悬浮窗
现在各种网站都喜欢加入position:fixed的悬浮窗,这些悬浮窗可以是分享按钮,可以是二维码,可以是各种烦人的按钮. 因为这些悬浮窗未必是广告,所以adblock很少自动屏蔽它们. 可这些悬浮窗 ...
- HDU 6438"Buy and Resell"(贪心+优先级队列)
传送门 •参考资料 [1]:HDU6438(优先队列+思维) •题意 有n个城市,第 i 天你会达到第 i 个城市: 在第 i 个城市中,你可以用 ai 元购买一个物品,或者用 ai 元卖掉一个物品, ...
- Spring Boot Admin-应用健康监控后台管理
Spring Boot Admin 用于监控基于 Spring Boot 的应用,它是在 Spring Boot Actuator 的基础上提供简洁的可视化 WEB UI. 1. 什么是Spring ...
- EJB实例
两种管理机制: 无状态bean使用实例池技术管理bean 有状态bean使用激活(activation)管理bean 内存对象序列化到磁盘 磁盘反序列化到内存