1. 程式人生 > >git 匯出版本之間差異檔案

git 匯出版本之間差異檔案

檢視 commit id

首先用 git log 檢視版本庫日誌,找出需要匯出的 commit id

$ git log --pretty=oneline
456bcbccd91278f7fdf6bf11bc73c4e3a6193c7f (HEAD -> www.xxx.com) 搜尋新增翻頁
4416b97c1c67efb83f63bd60af8244105471f3db Merge branch 'master' into www.xxx.com
ffd7d3c29d92dcbb6239401dd997a38d6adf554b (master) 將分頁檢視釋出到專案中,方便自定義分頁
68
ea66ca296f41e62951ae96aa59fdd7b2848317 給搜尋路由加上名稱 93593adac0bce680e63d202057c8128ccd9ea82b (origin/www.xxx.com) 調整頁尾的網址 f07871038329dccf00a4deb66d7898bd1015c2e1 修正首頁輪播圖小點的問題 f5ce56385f0cff7817619c7577600ea995f10994 Merge branch 'master' into www.xxx.com 7b7354817681392cf3696629bb9032960216ade9 (origin/master) debug:從欄目複製導航的時候,會報錯 690
c7826a076b49b401d55534d83263b8b15348a Merge branch 'master' into www.xxx.com 003dc9aa6ed0c4b6009e782e87585bd2eaefddac 文章新增 seo 資訊,欄目刪除 seo 標題欄位 12f2da2c00ececb59eab05ed34c259d6167fd41a 新增文章、欄目 seo 資訊 e11b00c72a669f13de51f80ce4c1152500eed250 完成文章詳情頁面套模板 697013ee07c4904e954e468431d8e54634111a3e 合併主幹 c6718cf018b62178711ed482aa7509d16e6c5e21 開啟文章、欄目新增點選量 aa300af58a0c929ff6a6ac97a949fea4146cca7c Merge branch 'master'
into www.xxx.com

找出差異檔案

使用 git diff 命令可以檢視提交之間的外掛,使用 --name-only 引數只顯示檔名

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

輸出結果就是所有的差異檔案,下面再使用 xargs 將檔案進行下一步處理

將差異檔案打包

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

這樣,../update.tar.gz 檔案就有所有更新的檔案

直接複製出差異檔案

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

xargs -t -i{} cp --parents {} ../update 的引數說明

  • -t:顯示執行的命令
  • -i{}:將前面的輸入作為一個佔位符 {} 在後面使用