git commit 合并

  • 日常 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
  • 经验证,这篇文章有点小问题,让我有时间再更正一下

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值