Tbpgr Blog

Employee Experience Engineer tbpgr(てぃーびー) のブログ

Git | リベース

概要

リベース

詳細

マージと異なり、履歴が一本化されます。

前提

下記のような操作をするところから開始

  • masterからtopicブランチを作成
  • topicブランチで1つの修正を行いコミットをする(修正topic1とする)
  • masterブランチで1つの修正を行いコミットをする(修正master1とする)
マージの場合
$ git checkout master
$ git merge topic
$ git log -10 --graph --decorate --oneline
*   0c410c6 (HEAD, master) Merge branch 'topic'
|\
| * 6813c6a (topic) fix topic
* | aab718f master change
|/
* f615d15
リベースの場合
$ git branch
  master
* topic
$ git rebase master
# conflict 発生
$ git status
# Not currently on any branch.
# Unmerged paths:
#   (use "git reset HEAD <file>..." to unstage)
#   (use "git add/rm <file>..." as appropriate to mark resolution)
#
#       both modified:      hoge.txt
#
no changes added to commit (use "git add" and/or "git commit -a")
# conflict解消
$ vi hoge.txt
$ git add .
$ git status
# Not currently on any branch.
# Changes to be committed:
#   (use "git reset HEAD <file>..." to unstage)
#
#       modified:   hoge.txt
#
$ git branch
* (no branch)
  master
  topic
$ git rebase --continue
Applying: change in topic
$ git log -10 --graph --decorate --oneline
* 2660fa2 (HEAD, topic) change in topic
* 7daaa51 (master) change in master
* dff828b add hoge.txt
$ git checkout master
Switched to branch 'master'
$ git merge topic
Updating 7daaa51..2660fa2
Fast-forward
 hoge.txt |    3 +--
 1 files changed, 1 insertions(+), 2 deletions(-)
$ git log -10 --graph --decorate --oneline
* 2660fa2 (HEAD, topic, master) change in topic
* 7daaa51 change in master
* dff828b add hoge.txt