• Git cherry-pick 复制 commit


    应用背景

    当你写完代码 commit 完心中暗爽,正准备 push 时,突然发现原来自己当前分枝就在 master 上,master 只能用来上线打版本,当然不能直接操作,可惜现在剁手也晚了。

    那么总有一种办法可以把 master 上的 commit 复制一份去 develop 上,答案就是 cherry-pick。

    使用方法

    $ git checkout master
    $ git log
    
    commit a2dee88e23ed33c7975f9f26aeb215de0fbd7c28
    Author: 陈子云 <chentongta@souche.com>
    Date:   Wed Nov 14 11:18:09 2018 +0800
    
        fix: 修复从模板跳转去其他页面附带参数没有被正常解析的bug。模版新增跳转发送短信的功能
    
    

    得到 commit id 为 a2dee88e23ed33c7975f9f26aeb215de0fbd7c28,接着切换去 develop 分支操作

    $ git checkout develop
    $ git cherry-pick 'a2dee88e23ed33c7975f9f26aeb215de0fbd7c28'
    
    Finished one cherry-pick.
    # On branch dev
    # Your branch is ahead of 'origin/dev' by 1 commits.
    
    # 如果有多个 commit,取最前方的 commit id,cherry-pick 后会显示
    
    
    
    

    上面的提示信息告诉我们这个 commit 已经重新提交到了 dev 分支下.

    注意, 这个操作也行会报错, 这时需要你手动去合并冲突, 然后重新提交.

    如果有多个 commit,取最前方的 commit id,cherry-pick 后会显示

    $ git checkout develop
    $ git cherry-pick 'a2dee88e23ed33c7975f9f26aeb215de0fbd7c28'
    
    On branch develop
    You are currently cherry-picking commit 879ccd1.
    
    nothing to commit, working tree clean
    The previous cherry-pick is now empty, possibly due to conflict resolution.
    If you wish to commit it anyway, use:
    
        git commit --allow-empty
        
    $ git commit --allow-empty
    
    [develop 0d69c42] fix: 修复从模板跳转去其他页面附带参数没有被正常解析的bug。模版新增跳转发送短信的功能
     Date: Wed Nov 14 11:19:08 2018 +0800
    

    最后 git push

  • 相关阅读:
    python学习笔记(十五)-异常处理
    python学习笔记(十四)python实现发邮件
    python学习笔记(十三)-python对Excel进行读写修改操作
    python学习笔记(十二)-网络编程
    python学习笔记(十一)-python程序目录工程化
    python学习笔记(九)-函数2
    python学习笔记(八)-模块
    勿忘初心,勇往前行
    【tp6】解决Driver [Think] not supported.
    【Linux】LNMP1.6 环境报500错误解决方法
  • 原文地址:https://www.cnblogs.com/everlose/p/12825906.html
Copyright © 2020-2023  润新知