Gitlab+Jenkins学习之路(五)之git merge和git rebase的区别

命令行测试

[root@linux-node1 ~]# mkdir testing
[root@linux-node1 ~]# 
[root@linux-node1 ~]# cd testing/
[root@linux-node1 testing]# 
[root@linux-node1 testing]# git init
Initialized empty Git repository in /root/testing/.git/
[root@linux-node1 testing]# echo "123" > index.html
[root@linux-node1 testing]# git add .
[root@linux-node1 testing]# git commit -m "first commit"
[master (root-commit) b712131] first commit
 1 file changed, 1 insertion(+)
 create mode 100644 index.html
[root@linux-node1 testing]# echo "a file" > a.txt
[root@linux-node1 testing]# git add .
[root@linux-node1 testing]# git commit -m "add a.txt"
[master 025e8a3] add a.txt
 1 file changed, 1 insertion(+)
 create mode 100644 a.txt
[root@linux-node1 testing]# echo "b file" > b.txt
[root@linux-node1 testing]# git add .
[root@linux-node1 testing]# git commit -m "add b.txt"
[master f4b13b6] add b.txt
 1 file changed, 1 insertion(+)
 create mode 100644 b.txt
[root@linux-node1 testing]# git log
commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:36 2017 +0800
    add b.txt
commit 025e8a337bfe312065d93b040852ceb532ef6642
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:12 2017 +0800
    add a.txt
commit b712131d81e3224f72f97c76f855e28da413450e
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:21:35 2017 +0800
    first commit
[root@linux-node1 testing]# git checkout -b dev
Switched to a new branch 'dev'
[root@linux-node1 testing]# git status
On branch dev
nothing to commit, working directory clean
[root@linux-node1 testing]# git log
commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:36 2017 +0800

    add b.txt

commit 025e8a337bfe312065d93b040852ceb532ef6642
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:12 2017 +0800

    add a.txt

commit b712131d81e3224f72f97c76f855e28da413450e
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:21:35 2017 +0800

    first commit
[root@linux-node1 testing]# echo "welcome to beijing" > test1.txt
[root@linux-node1 testing]# git add .
[root@linux-node1 testing]# git commit -m "test1"
[dev d224e8c] test1
 1 file changed, 1 insertion(+)
 create mode 100644 test1.txt
[root@linux-node1 testing]# echo "welcome to shanghai" > test2.txt
[root@linux-node1 testing]# git add .
[root@linux-node1 testing]# git commit -m "test2"
[dev e254dd5] test2
 1 file changed, 1 insertion(+)
 create mode 100644 test2.txt
[root@linux-node1 testing]# git log
commit e254dd5657d99ed287faf62f74b566a7ac1bf858
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:26:01 2017 +0800

    test2

commit d224e8cb4a51a65377c8d8eb75c3613b197e47a4
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:25:37 2017 +0800

    test1

commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:36 2017 +0800

    add b.txt

commit 025e8a337bfe312065d93b040852ceb532ef6642
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:12 2017 +0800

    add a.txt

commit b712131d81e3224f72f97c76f855e28da413450e
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:21:35 2017 +0800

    first commit
[root@linux-node1 testing]# git checkout master
Switched to branch 'master'
[root@linux-node1 testing]# git status
On branch master
nothing to commit, working directory clean
[root@linux-node1 testing]# echo "master1" > master1.txt
[root@linux-node1 testing]# git add .
[root@linux-node1 testing]# git commit -m "master1"
[master 1ebe653] master1
 1 file changed, 1 insertion(+)
 create mode 100644 master1.txt
[root@linux-node1 testing]# echo "master2" > master2.txt
[root@linux-node1 testing]# git add .
[root@linux-node1 testing]# git commit -m "master2"
[master 814b217] master2
 1 file changed, 1 insertion(+)
 create mode 100644 master2.txt
[root@linux-node1 testing]# git log
commit 814b217ae84ca4ad541c36d96e9b3c2744bca849
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:28:15 2017 +0800

    master2

commit 1ebe65348f73958eeafce158f922d83e386faa78
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:27:50 2017 +0800

    master1

commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:36 2017 +0800

    add b.txt

commit 025e8a337bfe312065d93b040852ceb532ef6642
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:12 2017 +0800

    add a.txt

commit b712131d81e3224f72f97c76f855e28da413450e
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:21:35 2017 +0800

    first commit
[root@linux-node1 testing]# git merge dev
Merge made by the 'recursive' strategy.
 test1.txt | 1 +
 test2.txt | 1 +
 2 files changed, 2 insertions(+)
 create mode 100644 test1.txt
 create mode 100644 test2.txt
[root@linux-node1 testing]# git log
commit df1da42a6c93152001199d684f01702eb6cb622f
Merge: 814b217 e254dd5
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:29:35 2017 +0800

    Merge branch 'dev'

commit 814b217ae84ca4ad541c36d96e9b3c2744bca849
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:28:15 2017 +0800

    master2

commit 1ebe65348f73958eeafce158f922d83e386faa78
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:27:50 2017 +0800

    master1

commit e254dd5657d99ed287faf62f74b566a7ac1bf858
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:26:01 2017 +0800

    test2

commit d224e8cb4a51a65377c8d8eb75c3613b197e47a4
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:25:37 2017 +0800

    test1

commit f4b13b6d3fc390eacb59e0d6223ac37329d96d6f
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:36 2017 +0800

    add b.txt

commit 025e8a337bfe312065d93b040852ceb532ef6642
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:22:12 2017 +0800

    add a.txt

commit b712131d81e3224f72f97c76f855e28da413450e
Author: xiaoming <xiaoming@163.com>
Date:   Thu Dec 21 14:21:35 2017 +0800

    first commit

此时,整个分支合并图如下:

分支的状态会保留

image.png

 

如果使用git rebase dev,分支合并图如下:

分支的状态会清除

image.png

 

posted @ 2018-08-10 10:38  烟雨浮华  阅读(2062)  评论(0编辑  收藏  举报