一、补丁

生成补丁

[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

最新文章

  1. MVC4做网站后台:用户管理 ——用户组
  2. C# 委托应用总结
  3. css设置background图片的位置实现居中
  4. varchar类型转换为numeric的值时有问题原因
  5. windows server 2008/2012 无法安装AD域解决方法记录
  6. -bash: ./job.sh: /bin/sh^M: bad interpreter: 没有那个文件或目录
  7. Qt之新手打包发布程序
  8. 前端请求参数MD5加密校验,参数串解密
  9. require()的工作流程
  10. OVS常用命令
  11. git命令简介
  12. 如何查看jar包的版本号?(转)
  13. spring boot整合websocket
  14. Leetcode_5.最长回文子串
  15. Django Rest Framework-介绍
  16. saltStack运维工具的部署及master迁移实现的过程详解
  17. pandas 常用清洗数据(二)
  18. Django(ORM查询1)
  19. c++11 基于范围的for循环
  20. java jsch 登录linux系统避免手动输入Yes 或Always

热门文章

  1. 如何把IOS应用,发给别人测试?
  2. handlebears使用
  3. spring could Windows打包构建docker镜像到linux
  4. 170502、linux下配置jdk8
  5. Java之Tomcat、Dynamic web project与Servlet
  6. Docker与virtualenv
  7. python基础-第三篇-函数编程
  8. openresty环境搭建问题记录
  9. Windows使用中的一些小技巧
  10. 在django中实现支付宝支付(支付宝接口调用)