Git Rebase to keep commit log clean

There always be the cases that we are developing a new feature on seperate branch when we are using Git. There are many commit log like “fix type”, “correct the error” etc. When we merge the branch to master branch, we don’t want these stupid commit log appear in the commit log of master branch.

To merge development branch to master branch:

1
2
git checkout master
git merge development

If we want to make our commit log clean, then you should use rebase.

Rebase

example:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
# 开始开发一个新 feature
$ git checkout -b new-feature master
# 改了一些代码
$ git commit -a -m "Start developing a feature"
# 刚刚的修改有点问题,再改一下
$ git commit -a -m "Fix something from the previous commit"

# 紧急修复,直接在 master 分支上改点东西
$ git checkout master
# 改了一些代码
$ git commit -a -m "Fix security hole"

# 开始交互式地 rebase 了
$ git checkout new-feature
$ git rebase -i master

Reference

  1. Git tips: 合并 commit 保持分支干净整洁