• 日常 git 管理代码的时候,经常因为因为一些小的代码改动而进行一次 git commit , 但是这样造成的后果就是小的 git commit 很多很杂。

  • 今天特意的研究了一些 git commit 的合并方法。

  • 首先,使用 git log 看 log 信息。

    root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git log
commit 93ba40a42595edcbdb5adbab33d8c2dc5409f330
Author: root <root@aplex.(none)>
Date: Mon Nov 13 16:45:55 2017 +0800 ADD empty directory commit 0e35ffa5bdb248464ff2c6587b33206e021d86fc
Author: root <root@aplex.(none)>
Date: Mon Nov 13 16:37:43 2017 +0800 CMI-AT1010 filesystem init
  • 这里我们看到有两个 git commit , HASH Z值分别为 93ba40a4259 和 0e35ffa5bdb

  • 这里,我们 使用 git rebase -i HEAD~1 进行合并

    squash 93ba40a ADD empty directory          # 将要合并的 commit 

    # Rebase 0e35ffa..93ba40a onto 0e35ffa
#
# Commands:
# p, pick = use commit 使用这个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
#
# If you remove a line here THAT COMMIT WILL BE LOST.
# However, if you remove everything, the rebase will be aborted.
# Init CMI-AT101 filesystem # commit message
    保存退出
新的commit 生成
  • 如果操作有误,可以使用 git rebase --abort 进行恢复

    root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git log
commit 0e35ffa5bdb248464ff2c6587b33206e021d86fc
Author: root <root@aplex.(none)>
Date: Mon Nov 13 16:37:43 2017 +0800 CMI-AT1010 filesystem init
root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git rebase --abort
root@aplex:/home/cmi_at101/test/filesystem_test/cmi_at101_filesystem# git log
commit 93ba40a42595edcbdb5adbab33d8c2dc5409f330
Author: root <root@aplex.(none)>
Date: Mon Nov 13 16:45:55 2017 +0800 ADD empty directory commit 0e35ffa5bdb248464ff2c6587b33206e021d86fc
Author: root <root@aplex.(none)>
Date: Mon Nov 13 16:37:43 2017 +0800 CMI-AT1010 filesystem init
  • 经验证,这篇文章有点小问题,让我有时间再更正一下

git commit 合并的更多相关文章

  1. git commit 合并到指定分支

    1. 将指定的commit合并到当前分支 git cherry-pick  commit_id 2. 合并多个连续 commit 到指定分支 假设需要合并 devlop 上从 fb407a3f 到 9 ...

  2. git cherry-pick合并某个commit

    1.使用方法及其作用 git cherry-pick可以选择某一个分支中的一个或几个commit(s)来进行操作(操作的对象是commit).例如,假设我们有个稳定版本的分支,叫v2.0,另外还有个开 ...

  3. git commit -am 合并操作

    二,合并的操作 1, 首先按需修改文件 echo >> lz66303.txt 2, 然后按需提交被修改的文件到HEAD缓存区,并把这个修改记录到分支中 git commit -am&qu ...

  4. Git自动化合并多个Commit

    目录 git rebase逻辑 git editor的修改 处理git-rebase-todo文件 Python实现 当我们有多个commit或者从开源处拿到多个commit时,想合成一个commit ...

  5. git将多个commit合并成一个

    1. 查看提交历史(最近10个) git log - 2. 回到前面第十个commit,且将后面九个commit提交的内容状态改为未提交 git reset commitID(第十个commit的ID ...

  6. git只合并某一个分支的某个commit

    第一种情况:只合并一个commit git checkout develop-hbb git cherry-pick 7c32be61 以上,7c32be61是develop上的一个fix bug的c ...

  7. git将多个commit合并成一个新的commit

    问题: 有以下commit: 323udd ede234 6e7s6e 要合并第一个和第二个commit 方法有二: 方法一 使用git rebase -i hash-id,-i表示以交互模式进行co ...

  8. [转] git merge 将多个commit合并为一条之--squash 选项

    [FROM] https://blog.csdn.net/themagickeyjianan/article/details/80333645 1.一般的做法(直接git merge) Git相对于C ...

  9. 巧用 git rebase 合并多个 commit。

    一.为什么需要合并多个 commit 呢?   有时候,我们开发一个功能. 修修补补 commit 了很多次,过多的 commit 会显得很复杂. 不够直观,不能比较清晰查看那些 commit 是对应 ...

随机推荐

  1. 【转】我离开了 Coverity

    我离开了 Coverity 在写这篇博文的时候,我已经不再是 Coverity 的员工了,我已经在今天下午向公司正式辞职. 走出公司的大门,我觉得一身的轻松.这是我几个月以来第一次感受到加州美丽的阳光 ...

  2. C++虚函数工作原理

    一.虚函数的工作原理      虚函数的实现要求对象携带额外的信息,这些信息用于在运行时确定该对象应该调用哪一个虚函数.典型情况下,这一信息具有一种被称为 vptr(virtual table poi ...

  3. 安装和配置SharePoint 2013 Workflow

    SharePoint 2013中的工作流概述 在SharePoint 2013中,Workflow(建立在Windows Workflow Foundation 4.5)和WCF承载在Workflow ...

  4. 10.翻译:EF基础系列---EF中的持久性

    原文链接:http://www.entityframeworktutorial.net/EntityFramework4.3/persistence-in-entity-framework.aspx ...

  5. Socket编程知识必学

    端口号常识:    端口号被从1 开始分配.    通常端口号超出255 的部分被本地主机保留为私有用途.    1到255 之间的号码被用于远程应用程序所请求的进程和网络服务.    每个网络通信循 ...

  6. 挖财大牛讲 Springboot工作流程

    转 Spring Boot Rock'n'Roll FuqiangWang - fujohnwang AT gmail DOTA com 2015-07-09 1 SpringBoot Intro 2 ...

  7. django -- 插入行的不同方式

    在django中行是Model的一个实例.也就是说一个Model的实例就对应着一行. 一.通过构造函数创建行: import django django.setup() from polls.mode ...

  8. Centos 7 使用iptables

    systemctl stop firewalld.service #停止firewall systemctl disable firewalld.service #禁止firewall开机启动 #安装 ...

  9. Socket网络编程--Libev库学习(2)

    这一小节讲各个观察器(Watcher) 在libev下面watcher相当于EventHandler这么一个概念,通常里面会绑定fd回调函数以及我们需要关注的事件. 然后一旦触发事件之后会触发我们使用 ...

  10. DCOS :私有云的物理基础架构管理引擎

    https://cloud.tencent.com/developer/article/1005598 一.引言 云计算经过多年的发展,逐渐从概念到渐为人认知.到接受.到现在全行业拥抱上云,云的客户也 ...