LoginSignup
10
10

More than 5 years have passed since last update.

git amで他人のコミットをパッチとして当てる方法

Posted at

Gitを使っていると、代理でパッチを当てたいときがでてきます。そういうときは、git-amコマンド1を使うことで、情報を欠落しないままコミットすることができます。

パッチを当てる手順

  1. Pull RequestやMerge Request、Commitから、メールパッチを作成する
  2. メールパッチをmail.patchとしてファイルに保存する
  3. git am mail.patch のようにしてコミットする

メールパッチを入手する

Pull RequestやMerge RequestのURIがある場合には、.patchにアクセスすることでメールパッチが入手できます。

Gitlabの例

Merge RequestのURI: https://gitlab.*****.net/******/*****/merge_requests/162
パッチのURI: https://gitlab.*****.net/******/*****/merge_requests/162.patch

GitHubの例

Pull RequestのURI: https://github.com/******/*****/pull/162/files
パッチのURI: https://github.com/******/*****/pull/162.patch

メールパッチの例

メールパッチは、次のようにdiffに加えてコミット時刻、メッセージ、メールアドレス、名前が一緒に入っています。git-amを利用することで、コミットの情報を欠落させないまま、コミット適用することができます。

From 838715587106f46dc8be4a6faf3ed8ce55ecfc5a Mon Sep 17 00:00:00 2001
From: Kohki YAMAGIWA <xxxxxxx@gmail.com>
Date: Mon, 20 Jul 2015 06:49:43 +0900
Subject: [PATCH] bagfix(labeling) & add assertion

---
 ccv.py | 17 +++++++++--------
 1 file changed, 9 insertions(+), 8 deletions(-)

diff --git a/ccv.py b/ccv.py
index 52698d4..b19e0b5 100644
--- a/ccv.py
+++ b/ccv.py
@@ -53,11 +53,12 @@ def ccv(src, tau=0, n=64):
     for a,c in zip(areas,coord):
       area_size = a[0]
       x,y = c[0], c[1]
-      bin_idx = int(ch[y,x]//(256//n))
-      if area_size >= tau:
-        alpha[bin_idx] = alpha[bin_idx] + area_size
-      else:
-        beta[bin_idx] = beta[bin_idx] + area_size
+      if (x < ch.shape[1]) and (y < ch.shape[0]):
+        bin_idx = int(ch[y,x]//(256//n))
+        if area_size >= tau:
+          alpha[bin_idx] = alpha[bin_idx] + area_size
+        else:
+          beta[bin_idx] = beta[bin_idx] + area_size
   return alpha, beta

参考資料


  1. git-amのamは、Apply a series of patches from a mailboxの略のようです。 

10
10
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
10
10