一、补丁

生成补丁

[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

GIT使用—补丁与钩子的更多相关文章

  1. Git打补丁常见问题

    Git打补丁常见问题 往往觉得得到某个功能的补丁就觉得这个功能我就已经成功拥有了,可是在最后一步的打补丁的工作也是须要相当慎重的,甚至有可能还要比你获取这个补丁花费的时间还要多.看到好多同行遇到这个问 ...

  2. Git 打补丁流程

    A. 使用git制作补丁时, 需要创建一个新的分支, 修改之后再提交只需要修改需要修改的文件, 并使用git -format-patch -M master 将当前的分支与主分支(master)进行比 ...

  3. git 的补丁使用方法

    1.生成补丁 format-patch可以基于分支进行打包,也可以基于上几次更新内容打包. 基于上几次内容打包 git format-patch HEAD^  有几个^就会打几个patch,从最近一次 ...

  4. Git 应用补丁报错 “sha1 information is lacking or useless”

    因为现场代码在客户局域网内,不能连接到公司网络,所以一般更新的时候都是打补丁, 然后在客户现场应用补丁,但是最近在应用补丁的时候出现了如下问题: ... fatal: sha1 information ...

  5. git打补丁、还原补丁

    打补丁.还原补丁 1.两个commit间的修改(包含两个commit,<r1>.<r2>表示两个提交的版本号,<r1>是最近提交) git format-patch ...

  6. git 系统中 post-receive 钩子不能正常执行 git pull 解决方法

    有一个需求是本地git在push到远程 git repo 之后,在远程服务器上自动在/dir/foo下执行 git pull 的操作.想来是一个很简单的需求,不就是在远程的 foo.git 仓库中的 ...

  7. GIT打补丁 - patch和diff应用

    一. 准备工作: [root@guangzhou gittest]# git br * master [root@guangzhou gittest]# git chk -b patch-test1 ...

  8. git 打补丁,即git review之后需要二次修改并提交代码

    假如代码已经push上去了,可是当review时,发现有地方需要修改,你可以继续在本地修改你的文件,之后git status查看修改的文件,然后git add修改的文件,此时不能直接git commi ...

  9. 利用Git钩子实现代码发布

    目录 1.什么是git钩子 2.安装一个钩子 3.常用的钩子脚本类型 3.1 客户端钩子 3.1.1 pre-commit 3.1.2 prepare-commit-msg 3.1.3 commit- ...

随机推荐

  1. 【黑金原创教程】 FPGA那些事儿《概念篇》

    简介一本讲述非软硬片上系统的书,另外还是低级建模的使用手册. 目录[黑金原创教程] FPGA那些事儿<概念篇>:File01 - 结构的玩笑[黑金原创教程] FPGA那些事儿<概念篇 ...

  2. LeetCode-Lowest Common Ancestor of a Binary Tre

    Given a binary tree, find the lowest common ancestor (LCA) of two given nodes in the tree. According ...

  3. 160426、JavaScript 秘密花园

    简介 关于作者 这篇文章的作者是两位 Stack Overflow 用户, 伊沃·韦特泽尔 Ivo Wetzel(写作) 和 张易江 Zhang Yi Jiang(设计). 贡献者 贡献者 中文翻译 ...

  4. Hadoop 启动脚本分析与实战经验

    start-all.sh脚本现在已经废弃,推荐使用start-dfs.sh和start-yarn.sh分别启动HDFS和YARN. 在新一代的Hadoop里面HDFS称为了统一存储的平台,而YARN成 ...

  5. Hibernate的多对多映射关系

    example: 老师(teacher)和学生(Student)就是一个多对多的关系吧?老师可以有多个学生,学生也可以由多个老师,那在Hibernate中多对多是怎样实现的呢?? 在Hibernate ...

  6. C#全角半角转换输出解决方法

    Microsoft.VisualBasic 命名空间 Strings 模块 StrConv 函数就具有大写/小写.全角/半角.中文简体/繁体等转换功能,字符串转换应该说是VB.NET的强项,是这样的: ...

  7. nested exception is java.lang.IllegalStateException: Context namespace element 'annotation-config' a

    公司还用的是spring低版本,今天用jre 8测试了一下,发现错误: Unexpected exception parsing XML document from class path resour ...

  8. Program terminated with signal SIGABRT, Aborted.

    linux C++ 程序 启动后就奔溃 #0 0x00007f01ee4c21f7 in raise () from /lib64/libc.so.6 #1 0x00007f01ee4c38e8 in ...

  9. datasnap rest Windows客户端编写

    首先吐槽一下XE关于datasnap的资料真的是太少了... 服务端用DSHTTPService1控件可以实现http接口方式的调用,返回的都是json格式数据,适用于跨平台解析. 这里着重强调一下d ...

  10. Junit 3.8.1 源码分析(一)

    写在前面:本文基于Junit3.8.1版本,因为这是我第一次进行源码学习,先从简单的源码开始学起 1. 示例代码 1.1 准备工作 下载Junit3.8.1的JAR包 需要下载junit-3.8.1- ...