用git rebase合并

合并issue3分支的时候,使用rebase可以使提交的历史记录显得更简洁。

现在暂时取消刚才的合并。

$ git reset --hard HEAD~

rebase前的历史记录

切换到issue3分支后,对master执行rebase。

$ git checkout issue3
Switched to branch 'issue3'
$ git rebase master
First, rewinding head to replay your work on top of it...
Applying: 添加pull的说明
Using index info to reconstruct a base tree...
<stdin>:13: new blank line at EOF.
+
warning: 1 line adds whitespace errors.
Falling back to patching base and 3-way merge...
Auto-merging myfile.txt
CONFLICT (content): Merge conflict in myfile.txt
Failed to merge in the changes.
Patch failed at 0001 添加pull的说明

When you have resolved this problem run "git rebase --continue".
If you would prefer to skip this patch, instead run "git rebase --skip".
To check out the original branch and stop rebasing run "git rebase --abort".

和merge时的操作相同,修改在myfile.txt发生冲突的部分。

连猴子都懂的Git命令
add 把变更录入到索引中
<<<<<<< HEAD
commit 记录索引的状态
=======
pull 取得远端数据库的内容
>>>>>>> issue3

rebase的时候,修改冲突后的提交不是使用commit命令,而是执行rebase命令指定 --continue选项。若要取消rebase,指定 --abort选项。

$ git add myfile.txt
$ git rebase --continue
Applying: 添加pull的说明

目前的历史记录

这样,在master分支的issue3分支就可以fast-forward合并了。切换到master分支后执行合并。

$ git checkout master
Switched to branch 'master'
$ git merge issue3
Updating 8f7aa27..96a0ff0
Fast-forward
 myfile.txt |    1 +
 1 files changed, 1 insertions(+), 0 deletions(-)

myfile.txt的最终内容和merge是一样的,但是历史记录如下。

目前的历史记录

from: https://backlog.com/git-tutorial/cn/stepup/stepup2_8.html

猜你喜欢

转载自blog.csdn.net/GarfieldEr007/article/details/85320232
今日推荐