LoginSignup
19
19

More than 5 years have passed since last update.

GitHubの3種類のマージを理解する

Last updated at Posted at 2018-04-14

wataash/git-test-github-merge の和訳です。

GitHubではプルリクエストをマージする際、3種類のマージの仕方を選べます。

  • Create a merge commit
  • Squash merge
  • Rebase and merge

この記事では、tig コマンドでコミットグラフを見ながら、これらのマージの動作を直感的に説明したいと思います。

プルリクエストとマージ先

image

こんな感じ。pull-requestmaster にマージします。tig master pull-request で描画しました。

Create a merge commit

image

皆さんご存知。

Squash and merge

image

1つのコミットにsquashされる。ここで、commit authorがマージした人 (wataash) になることに注意して下さい。
git show --pretty=full squash-and-merge:

commit decb2967fed0c8bf776055abdeeb70db5c4680e3 (origin/squash-and-merge, squash-and-merge)
Author: Wataru Ashihara <wataash@users.noreply.github.com>
Commit: GitHub <noreply@github.com>

    Try "Squash and merge" (#2)

    * commit C

    * commit D

diff --git a/c.txt b/c.txt
new file mode 100644
index 0000000..e69de29
diff --git a/d.txt b/d.txt
new file mode 100644
index 0000000..e69de29

元のauthorの "Donald Dijkstra <donald@example.com>", "Charles Codd <charles@example.com>" がマージした人の "Wataru Ashihara <wataash@users.noreply.github.com>\" になってしまいました。コミッターは "GitHub noreply@github.com" になります。git的にはこの2人のcontributionsが無くなったように見え、"Insights" にも表示されなくなるのでオススメしません。Squashする場合は git rebase --interactive を使いましょう。

Rebase and merge

image

master の先につきます。Authorの書き換えはありませんが、Committerは GitHub Name <account@users.noreply.github.com> になります。git log --pretty=full -2 rebase-and-merge:

commit 24c02be4250587e26ded87f84ba157414593f35f (origin/rebase-and-merge, rebase-and-merge)
Author: Donald Dijkstra <donald@example.com>
Commit: Wataru Ashihara <wataash@users.noreply.github.com>

    commit D

commit 6fa84589a2af5f3234d647a097046f4e7847c420
Author: Charles Codd <charles@example.com>
Commit: Wataru Ashihara <wataash@users.noreply.github.com>

    commit C
19
19
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
19
19