shell腳本整理git修改前後

    之前用svn,圖形化界面,可以很容易導出修改前後,以文件的形式。然後用beycond compare進行對比,很好用。

使用git沒發導出修改前後,只能看diff文件,顯示不全。

所以製作了一個shell腳本,不是太完善,還能用。

使用方法:

1、修改DIR爲想要DIR爲修改前後存放的地方,修改head_hash爲git log最後的hash

2、把源碼文件存爲commit_befor_after.sh放到可以執行git命令的地方,然後執行

./commit_befor_after.sh hash1_before hash2_after

其中hash1_before是修改前的hash,hash2_after是修改後的hash。

執行完畢後在~/commit_befor_after下就可以看到修改前後。

另外會在當前文件夾下產生list.txt文件,裏面存放的是修改文件清單。

3、源碼如下,根據需要可以自己修改。

#!/bin/sh
DIR=~/commit_befor_after
head_hash=XXXXXXXXXX

echo The before hash:"$1"
echo The after  hash:"$2"

rm ${DIR}/before/ -rf
rm ${DIR}/after/ -rf
mkdir -p ${DIR}/before/
mkdir -p ${DIR}/after/

echo git diff --name-status "$1" "$2"
cmd1=$(echo git diff --name-status "$1" "$2")
$cmd1| awk '{print $2}' > list.txt

filelist=$(cat list.txt)
echo $filelist
echo

 echo ----------work begin------------------------------------
 echo git reset "$2" begin
 git reset "$2" --hard
 
 for file in $filelist
do
 echo cp --parents ${file} ${DIR}/after/
 cp --parents ${file} ${DIR}/after/  
done

echo  
 echo git reset "$1"
 git reset "$1" --hard
 
for file in $filelist
do
 echo cp --parents ${file} ${DIR}/before/
 cp --parents ${file} ${DIR}/before/
done

 echo
 echo git reset--hard HEAD
 git reset $head_hash --hard
 echo ----------work end-------------------------------------

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章