zoukankan      html  css  js  c++  java
  • GIT使用—补丁与钩子

    一、补丁

    生成补丁

    [root@localhost buding]# echo B > file;git add file;git commit -m "B"
    [master a8a93f8] B
     1 files changed, 1 insertions(+), 1 deletions(-)
    [root@localhost buding]# echo C >> file;git add file;git commit -m "C"
    [master 9eae16f] C
     1 files changed, 1 insertions(+), 0 deletions(-)
    [root@localhost buding]# echo D >> file;git add file;git commit -m "D"
    [master e2f238b] D
     1 files changed, 1 insertions(+), 0 deletions(-)
    [root@localhost buding]# cat file 
    B
    C
    D
    
    [root@localhost buding]# git show-branch --more=5 master
    [master] D
    [master^] C
    [master~2] B
    [master~3] A
    
    [root@localhost buding]# git format-patch -1
    0001-D.patch
    [root@localhost buding]# git format-patch -2
    0001-C.patch
    0002-D.patch
    [root@localhost buding]# git format-patch -3
    0001-B.patch
    0002-C.patch
    0003-D.patch
    [root@localhost buding]# git format-patch master~2..master
    0001-C.patch
    0002-D.patch
    [root@localhost buding]# cat 0001-B.patch 
    From a8a93f836eacad245b518a3c92f2e17c2fc984a6 Mon Sep 17 00:00:00 2001
    From: tong <tong@test.com>
    Date: Wed, 28 Feb 2018 12:00:06 +0800
    Subject: [PATCH 1/3] B
    
    ---
     file |    2 +-
     1 files changed, 1 insertions(+), 1 deletions(-)
    
    diff --git a/file b/file
    index f70f10e..223b783 100644
    --- a/file
    +++ b/file
    @@ -1 +1 @@
    -A
    +B
    -- 
    1.7.1
    

    应用补丁

    git am /tmp/buding/0001-C.patch
    

    二、钩子

    当版本库出现提交或补丁这样的特殊事件时,会触发执行一个或多个任意的脚本。

    • 前置(pre)钩子
      会在动作完成前调用,要在变更应用前进行批准、拒绝或调整操作,可以使用这种钩子
    • 后置(post)钩子
      在动作完成之后调用,常用来触发邮件通知或进行额外处理

    安装钩子

    [root@localhost buding]# cat .git/hooks/pre-commit.sample 
    #!/bin/sh
    ......
    
    if git rev-parse --verify HEAD >/dev/null 2>&1
    then
    	against=HEAD
    else
    	# Initial commit: diff against an empty tree object
    	against=4b825dc642cb6eb9a060e54bf8d69288fbee4904
    fi
    .........
    

    创建一个钩子

    [root@localhost tmp]# mkdir hooktest
    [root@localhost tmp]# cd hooktest/
    [root@localhost hooktest]# git init
    Initialized empty Git repository in /tmp/hooktest/.git/
    [root@localhost hooktest]# touch a b c
    [root@localhost hooktest]# git add a b c
    [root@localhost hooktest]# git commit -m "added a, b, and c"
    [master (root-commit) c9ecaec] added a, b, and c
     0 files changed, 0 insertions(+), 0 deletions(-)
     create mode 100644 a
     create mode 100644 b
     create mode 100644 c
    
    创建一个钩子,用来阻止包含“broken”这个词的变更被检入
    vim pre-commit
    echo "Hello, I'm a pre-commit script!" >&2
    if git diff --cached | grep '^+' | grep -q 'broken';then
        echo "ERROR:Can't commit the word 'broken'" >&2
        exit 1 # reject
    fi
    exit 0 # accept
    
  • 相关阅读:
    vue 解决 打包完iE下空白
    多层josn数据 修改
    vue 初始化data中的数据
    图片查看器(缩放 拖动)
    js 懒加载
    css flex 兼容ios android--商品展示 添加购物车
    领域驱动架构(DDD)建模
    知乎复制文本
    Nlog配置文件
    未能加载文件或程序集“xxx”或它的某一个依赖项。生成此程序集的运行时比当前加载的运行时新,无法加载此程序集
  • 原文地址:https://www.cnblogs.com/tongxiaoda/p/8482903.html
Copyright © 2011-2022 走看看