git、svn代码review

场景

1.比较同一个分支下,同一个文件的最新版本之间的差异

2.比较不同分支下,同一个文件的最新版本之间的差异

GIT代码review

比较同一个分支下,同一个文件的最新版本之间的差异

在review时查看某次提交修改详情:

$ git show 0f27a652d

以上操作可以拆分为两步:

1.获取某次提交的sha-1值、提交者、提交时间、commitLog、变更文件列表
$ git show 0f27a65 --name-only --pretty=format:"%h,%cn,%cr,%s"
0f27a65,范金,28 hours ago,MS-9 流水线 - 流水线执行
src/pages/PublishManage/PipelineDetailView/PipelineDetailLayout.js
src/pages/PublishManage/PipelineEditView/PipelineEditView.js
src/pages/PublishManage/PipelineEditView/pipelineStepTemplate/AppDbCheck.js
或者只需要变更文件列表:
$ git show 0f27a652d --name-only --pretty=format:""
src/pages/PublishManage/PipelineDetailView/PipelineDetailLayout.js
src/pages/PublishManage/PipelineEditView/PipelineEditView.js
src/pages/PublishManage/PipelineEditView/pipelineStepTemplate/AppDbCheck.js
2.查看某个文件在某次提交中的修改:
$ git show <hashcode> <filename>

比较不同分支下,同一个文件的最新版本之间的差异

如果从master合向DAT分支;即查看master中有,而DAT中没有的内容:

$ git log master ^DAT --pretty=format:"%h,%an,%ar,%s" --grep "MS-9 "
c62818d,张帅,6 days ago,Merge branch 'master' into 'master'
0f27a65,范金,6 days ago,MS-9 流水线 - 流水线执行
2b2be9e,张帅,7 days ago,Merge branch 'master' into 'master'
499b5e9,范金,7 days ago,MS-9 流水线 - 流水线执行
1024ffd,张帅,12 days ago,Merge branch 'master' into 'master'
fb399d1,范金,12 days ago,MS-9 流水线 - 流水线执行

获取某次提交的sha-1值、提交者、提交时间、commitLog、变更文件列表

$ git show 0f27a65 --name-only --pretty=format:"%h,%an,%ar,%s"
0f27a65,范金,28 hours ago,MS-9 流水线 - 流水线执行
src/pages/PublishManage/PipelineDetailView/PipelineDetailLayout.js
src/pages/PublishManage/PipelineEditView/PipelineEditView.js
src/pages/PublishManage/PipelineEditView/pipelineStepTemplate/AppDbCheck.js

查看某个文件在某次提交中的修改:

$ git show <hashcode> <filename>

查看两个分支的差异文件列表

$ git diff master DAT --name-only
config/config.js
config/router.config.js
package.json
src/components/PageHeader/index.js
src/global.less
src/locales/zh-CN.js

查看两个分支的指定文件的详细差异

(分支名顺序:如果从master合向DAT分支,一定是DAT在前,master在后)

$ git diff DAT master -- config/config.js
diff --git a/config/config.js b/config/config.js
index a51e98b..d0edada 100755
--- a/config/config.js
+++ b/config/config.js
@@ -34,12 +34,12 @@ export default {
: {}),
},
],
- // [
- // 'umi-plugin-ga',
- // {
- // code: 'UA-72788897-6',
- // },
- // ],
+ [
+ 'umi-plugin-ga',
+ {
+ code: 'UA-72788897-6',
+ },
+ ],
],
targets: {
ie: 11,

查看跨分支的某两个版本的指定文件内容差异

(版本号顺序:如果从master合向DAT分支,一定是DAT在前,master在后)

$ git diff 324c152f df309e71 config/config.js
diff --git a/config/config.js b/config/config.js
index d0edada..58be130 100755
--- a/config/config.js
+++ b/config/config.js
@@ -95,7 +95,7 @@ export default {
},
],
},
- hash:true,//构建文件添加hash值
+
// chainWebpack: webpackplugin, //打包后图片路径指向问题
cssnano: {
mergeRules: false,

SVN代码review

根据版本号获取提交信息

E:\testSvnCommons\testSvn>svn log -r 7
------------------------------------------------------------------------
r7 | liuyongzhan | 2018-12-04 17:01:53 +0800 (周二, 04 12月 2018) | 1 line
AC-6 add test2、test3,and modify test1
------------------------------------------------------------------------

也可以是远程的svn地址:

C:\WINDOWS\system32>svn log -r 7 svn://svnbucket.com/liuyongzhan/testSvn
------------------------------------------------------------------------
r7 | liuyongzhan | 2018-12-04 17:01:53 +0800 (周二, 04 12月 2018) | 1 line
AC-6 add test2、test3,and modify test1
-----------------------

比较同一个分支下,同一个文件,两个不同版本之间的差异

获取第5版本所有改动文件的列表:(即第4版本到第5版本所有改动文件的列表,不包含第4版本)

C:\Users\liuyongzhan\Desktop\Svn相关\testSvn>svn diff -r 4:5 --summarize
A trunk\tes2.txt
M trunk\test1.txt
A trunk\test3.txt
A trunk\test4.txt

也可以是远程的svn地址:

C:\Users\liuyongzhan\Desktop\Svn相关\testSvn>svn diff -r 4:5 --summarize svn://svnbucket.com/liuyongzhan/testSvn
A svn://svnbucket.com/liuyongzhan/testSvn/trunk/test4.txt
A svn://svnbucket.com/liuyongzhan/testSvn/trunk/tes2.txt
M svn://svnbucket.com/liuyongzhan/testSvn/trunk/test1.txt
A svn://svnbucket.com/liuyongzhan/testSvn/trunk/test3.txt

查看一个文件在版本5时的内容变化:(即5与4(5-1)之间的差异)

C:\Users\liuyongzhan\Desktop\Svn相关\testSvn>svn diff -r 4:5 trunk\test1.txt
Index: trunk/test1.txt
===================================================================
--- trunk/test1.txt (revision 4)
+++ trunk/test1.txt (revision 5)
@@ -1,2 +1,3 @@
add 2
-add test1
\ No newline at end of file
+add test1
+add test2、test3、test4
\ No newline at end of file

也可以是远程的svn地址:

svn diff -r 4:5 svn://svnbucket.com/liuyongzhan/testSvn/trunk/test1.txt
Index: test1.txt
===================================================================
--- test1.txt (revision 4)
+++ test1.txt (revision 5)
@@ -1,2 +1,3 @@
add 2
-add test1
\ No newline at end of file
+add test1
+add test2、test3、test4
\ No newline at end of file

比较不同分支下,同一个文件的最新版本之间的差异

查看两个分支(目录)的差异文件列表:

C:\Users\liuyongzhan\Desktop\Svn相关\testSvn>svn diff --summarize svn://svnbucket.com/liuyongzhan/testSvn/branches/ svn://svnbucket.com/liuyongzhan/testSvn/trunk/
A svn://svnbucket.com/liuyongzhan/testSvn/branches/test4.txt
A svn://svnbucket.com/liuyongzhan/testSvn/branches/tes2.txt
A svn://svnbucket.com/liuyongzhan/testSvn/branches/test1.txt
A svn://svnbucket.com/liuyongzhan/testSvn/branches/test3.txt

查看文件内容差异:

C:\Users\liuyongzhan\Desktop\Svn相关\testSvn>svn diff svn://svnbucket.com/liuyongzhan/testSvn/branches/ svn://svnbucket.com/liuyongzhan/testSvn/trunk/
Index: tes2.txt
===================================================================
--- tes2.txt (.../branches) (nonexistent)
+++ tes2.txt (.../trunk) (revision 5)
@@ -0,0 +1 @@
+add test2
\ No newline at end of file
Index: test1.txt
===================================================================
--- test1.txt (.../branches) (nonexistent)
+++ test1.txt (.../trunk) (revision 5)
@@ -0,0 +1,3 @@
+add 2
+add test1
+add test2、test3、test4
\ No newline at end of file
Index: test3.txt
===================================================================
--- test3.txt (.../branches) (nonexistent)
+++ test3.txt (.../trunk) (revision 5)
@@ -0,0 +1 @@
+add test3
\ No newline at end of file
Index: test4.txt
===================================================================
--- test4.txt (.../branches) (nonexistent)
+++ test4.txt (.../trunk) (revision 5)
@@ -0,0 +1 @@
+add test4
\ No newline at end of file