当前位置:   article > 正文

Git 比较两个分支的差异_gitlab 分支对比

gitlab 分支对比

通常我们在一个分支实现一个功能,当开发测试完成后,合并到主分支,这是通常需要在合并分支前Code Reivew。

通常我们在Git Lab等工具进行Merge(Push Request)的时候就可以通过网页进行代码审查。而有时候Git Lab的网页对比工具的算法导致整个文件都被认为发生修改,不便于查看修改变更。

这时如果工作在Windows环境中,也可以使用TortoiseGit 工具进行比较,也是比较方便的。

如果我们工作在Linux命令行环境呢,就只能使用git tool了。下面介绍一下在Linux命令行下如何做代码审查。

首先拉取要比较的两个分支的最新代码:

[root@localhost tt_td]# git checkout drop_copy
Branch drop_copy set up to track remote branch drop_copy from origin.
Switched to a new branch 'drop_copy'
[root@localhost tt_td]# git pull
Already up-to-date.
  • 1
  • 2
  • 3
  • 4
  • 5

可以先查看有哪些文件发生改变,命令git diff branch_1 branch_2 --stat

[root@localhost tt_td]# git checkout master
Switched to branch 'master'
[root@localhost tt_td]# git diff master drop_copy --stat
 config/TT_gateway.yml              |   11 +-
 src/CMakeLists.txt                 |   14 +-
 src/gateway/CMakeLists.txt         |    1 +
 src/gateway/gateway.cpp            |  100 +++----
 src/tt_connect/Application.cpp     | 2337 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------
 src/tt_connect/Application.h       |  272 ++++++++++---------
 src/tt_connect/TTField.h           |   16 ++
 src/tt_connect/TTFixDefinedMsg.h   |   22 ++
 src/tt_connect/TTFixFieldNumbers.h |   21 ++
 src/tt_connect/config.h.in         |    1 +
 src/tt_connect/config_parser.h     |   83 ++++++
 src/tt_connect/tt_connect.cpp      |  249 ++++++++---------
 src/tt_connect/tt_connect.h        |   74 +++---
 13 files changed, 1766 insertions(+), 1435 deletions(-)
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17

最后可以借助vimdiff来查看文件内容的改动,命令:git difftool branch_1 branch_2,每次打开文件对比时,命令行会出现下面的提示文字,输入Y或者直接回车键即可:

[root@localhost tt_td]# git difftool master drop_copy

This message is displayed because 'diff.tool' is not configured.
See 'git difftool --tool-help' or 'git help config' for more details.
'git difftool' will now attempt to use one of the following tools:
kompare emerge vimdiff

Viewing: 'config/TT_gateway.yml'
Launch 'vimdiff' [Y/n]: Y
2 files to edit
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10

另外如果是只比较两个分支下的某个文件,可以使用命令:git difftool branch_1 branch_2 filename

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/977055
推荐阅读
相关标签
  

闽ICP备14008679号