dev 在 rebase master 后,由原来的两个分岔的分支,变成重叠的分支,看起来 dev 是从最新的 master 上拉出的分支。
什么时候使用 rebase / merge
假设场景:从 dev 拉出分支 feature-a。那么当 dev 要合并 feature-a 的内容时,使用 git merge feature-a;反过来当 feature-a 要更新 dev 的内容时,使用 git rebase dev。
使用时主要看两个分支的"主副"关系。
注意
一般来说,rebase后的 dev 和远程的origin/dev会发生分离,在命令行界面中会提示:
Your branch and 'origin/dev' have diverged,
and have 1 and 1 different commits each, respectively.
(use "git pull" to merge the remote branch into yours)
1 pick ffc75a4 修改
2 pick 6c2217f bbb
3 pick a615960 修改a 1
4 pick e4817b3 修改a 2
5 pick 8550690 修改a 3
6
7 # Rebase 3190ea4..8550690 onto 3190ea4 (5 command(s))
8 #
9 # Commands:
10 # p, pick = use commit
11 # r, reword = use commit, but edit the commit message
12 # e, edit = use commit, but stop for amending
13 # s, squash = use commit, but meld into previous commit
14 # f, fixup = like "squash", but discard this commit's log message
15 # x, exec = run command (the rest of the line) using shell
16 # d, drop = remove commit
17 #
18 # These lines can be re-ordered; they are executed from top to bottom.
19 #
20 # If you remove a line here THAT COMMIT WILL BE LOST.
21 #
22 # However, if you remove everything, the rebase will be aborted.
23 #
24 # Note that empty commits are commented out
b3bf634 HEAD@{0}: rebase -i (finish): returning to refs/heads/feature-rebase-i
b3bf634 HEAD@{1}: rebase -i (fixup): 完善a中的判断和输出
dd19de3 HEAD@{2}: rebase -i (fixup): # This is a combination of 2 commits.
c138acf HEAD@{3}: rebase -i (reword): 完善a中的判断和输出
a7f47b2 HEAD@{5}: rebase -i (start): checkout dev
a472934 HEAD@{6}: rebase: aborting
a7f47b2 HEAD@{7}: rebase -i (start): checkout dev
a472934 HEAD@{8}: commit: 添加a输出
c84d5b7 HEAD@{9}: commit: 添加a中的判断
a5a6e64 HEAD@{10}: commit: 修改a内容
a7f47b2 HEAD@{11}: checkout: moving from dev to feature-rebase-i