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
GIT使用—补丁与钩子的更多相关文章
- Git打补丁常见问题
Git打补丁常见问题 往往觉得得到某个功能的补丁就觉得这个功能我就已经成功拥有了,可是在最后一步的打补丁的工作也是须要相当慎重的,甚至有可能还要比你获取这个补丁花费的时间还要多.看到好多同行遇到这个问 ...
- Git 打补丁流程
A. 使用git制作补丁时, 需要创建一个新的分支, 修改之后再提交只需要修改需要修改的文件, 并使用git -format-patch -M master 将当前的分支与主分支(master)进行比 ...
- git 的补丁使用方法
1.生成补丁 format-patch可以基于分支进行打包,也可以基于上几次更新内容打包. 基于上几次内容打包 git format-patch HEAD^ 有几个^就会打几个patch,从最近一次 ...
- Git 应用补丁报错 “sha1 information is lacking or useless”
因为现场代码在客户局域网内,不能连接到公司网络,所以一般更新的时候都是打补丁, 然后在客户现场应用补丁,但是最近在应用补丁的时候出现了如下问题: ... fatal: sha1 information ...
- git打补丁、还原补丁
打补丁.还原补丁 1.两个commit间的修改(包含两个commit,<r1>.<r2>表示两个提交的版本号,<r1>是最近提交) git format-patch ...
- git 系统中 post-receive 钩子不能正常执行 git pull 解决方法
有一个需求是本地git在push到远程 git repo 之后,在远程服务器上自动在/dir/foo下执行 git pull 的操作.想来是一个很简单的需求,不就是在远程的 foo.git 仓库中的 ...
- GIT打补丁 - patch和diff应用
一. 准备工作: [root@guangzhou gittest]# git br * master [root@guangzhou gittest]# git chk -b patch-test1 ...
- git 打补丁,即git review之后需要二次修改并提交代码
假如代码已经push上去了,可是当review时,发现有地方需要修改,你可以继续在本地修改你的文件,之后git status查看修改的文件,然后git add修改的文件,此时不能直接git commi ...
- 利用Git钩子实现代码发布
目录 1.什么是git钩子 2.安装一个钩子 3.常用的钩子脚本类型 3.1 客户端钩子 3.1.1 pre-commit 3.1.2 prepare-commit-msg 3.1.3 commit- ...
随机推荐
- 【BZOJ3653】谈笑风生 离线+树状数组+DFS序
[BZOJ3653]谈笑风生 Description 设T 为一棵有根树,我们做如下的定义: ? 设a和b为T 中的两个不同节点.如果a是b的祖先,那么称“a比b不知道高明到哪里去了”. ? 设a 和 ...
- 【BZOJ4297】[PA2015]Rozstaw szyn 树形DP
[BZOJ4297][PA2015]Rozstaw szyn Description 给定一棵有n个点,m个叶子节点的树,其中m个叶子节点分别为1到m号点,每个叶子节点有一个权值r[i].你需要给剩下 ...
- ListView.setDivider,自定义的Devider
ListView lv = getListView(); ColorDrawable sage = new ColorDrawable(this.getResources().getColor(R.c ...
- ajax请求步骤
ajax步骤:第一步:创建xmlhttprequest对象,var xmlhttp = new XMLHttpRequest(); XMLHttpRequest对象和服务器交换数据.第二步:使用xml ...
- unicode转换中文
<!doctype html><html lang="en"> <head> <meta http-equiv="Refres ...
- Maven结构下 properties 读取
Properties properties = new Properties();InputStream in = ClassLoader.class.getResourceAsStream(&quo ...
- 论OI中无穷大(INF)的取值
水 为什么我的Floyd会输出负数啊? 为什么我的代码写对了却全都爆零了啊? 那么很可能是你的INF取大/小了! 那么inf到底应该取什么值呢? 首先,inf应该要比一般的题目中出现的数据要大,但是又 ...
- php+nginx上传文件配置
- 剑指Offer——数值的整数次方
题目描述: 给定一个double类型的浮点数base和int类型的整数exponent.求base的exponent次方. 分析: 快速幂,简单解释下, 当e的二进制为1001011, b^e=b^( ...
- okhttp发送post请求
String url = "http://www.xxx.com/api/test"; OkHttpClient httpClient = new OkHttpClient(); ...