git 导出版本之间差异文件

来源:互联网 发布:最近网络疯传的名校 编辑:程序博客网 时间:2024/05/22 04:52

查看 commit id

首先用 git log 查看版本库日志,找出需要导出的 commit id

$ git log --pretty=oneline456bcbccd91278f7fdf6bf11bc73c4e3a6193c7f (HEAD -> www.xxx.com) 搜索添加翻页4416b97c1c67efb83f63bd60af8244105471f3db Merge branch 'master' into www.xxx.comffd7d3c29d92dcbb6239401dd997a38d6adf554b (master) 将分页视图发布到项目中,方便自定义分页68ea66ca296f41e62951ae96aa59fdd7b2848317 给搜索路由加上名称93593adac0bce680e63d202057c8128ccd9ea82b (origin/www.xxx.com) 调整页脚的网址f07871038329dccf00a4deb66d7898bd1015c2e1 修正首页轮播图小点的问题f5ce56385f0cff7817619c7577600ea995f10994 Merge branch 'master' into www.xxx.com7b7354817681392cf3696629bb9032960216ade9 (origin/master) debug:从栏目复制导航的时候,会报错690c7826a076b49b401d55534d83263b8b15348a Merge branch 'master' into www.xxx.com003dc9aa6ed0c4b6009e782e87585bd2eaefddac 文章添加 seo 信息,栏目删除 seo 标题字段12f2da2c00ececb59eab05ed34c259d6167fd41a 添加文章、栏目 seo 信息e11b00c72a669f13de51f80ce4c1152500eed250 完成文章详情页面套模板697013ee07c4904e954e468431d8e54634111a3e 合并主干c6718cf018b62178711ed482aa7509d16e6c5e21 打开文章、栏目添加点击量aa300af58a0c929ff6a6ac97a949fea4146cca7c Merge branch 'master' into www.xxx.com

找出差异文件

使用 git diff 命令可以查看提交之间的插件,使用 --name-only 参数只显示文件名

$ git diff 456bcb 93593a --name-onlypublic/js/index.jsresources/views/index.blade.phpresources/views/public/pagination.blade.phpresources/views/search.blade.phpresources/views/vendor/pagination/bootstrap-4.blade.phpresources/views/vendor/pagination/default.blade.phpresources/views/vendor/pagination/semantic-ui.blade.phpresources/views/vendor/pagination/simple-bootstrap-4.blade.phpresources/views/vendor/pagination/simple-default.blade.php

输出结果就是所有的差异文件,下面再使用 xargs 将文件进行下一步处理

将差异文件打包

$ git diff 456bcb 93593a --name-only | xargs tar -czvf ../update.tar.gzpublic/js/index.jsresources/views/index.blade.phpresources/views/public/pagination.blade.phpresources/views/search.blade.phpresources/views/vendor/pagination/bootstrap-4.blade.phpresources/views/vendor/pagination/default.blade.phpresources/views/vendor/pagination/semantic-ui.blade.phpresources/views/vendor/pagination/simple-bootstrap-4.blade.phpresources/views/vendor/pagination/simple-default.blade.php

这样,../update.tar.gz 文件就有所有更新的文件

直接复制出差异文件

$ git diff 456bcb 93593a --name-only | xargs -t -i{} cp --parents {} ../updatecp --parents public/js/index.js ../updatecp --parents resources/views/index.blade.php ../updatecp --parents resources/views/public/pagination.blade.php ../updatecp --parents resources/views/search.blade.php ../updatecp --parents resources/views/vendor/pagination/bootstrap-4.blade.php ../updatecp --parents resources/views/vendor/pagination/default.blade.php ../updatecp --parents resources/views/vendor/pagination/semantic-ui.blade.php ../updatecp --parents resources/views/vendor/pagination/simple-bootstrap-4.blade.php ../updatecp --parents resources/views/vendor/pagination/simple-default.blade.php ../update

xargs -t -i{} cp --parents {} ../update 的参数说明

  • -t:显示执行的命令
  • -i{}:将前面的输入作为一个占位符 {} 在后面使用