Archive

Posts Tagged ‘git’

Sourcetree git diff script

August 4th, 2015 No comments

Git is great but it’s not always easy to know which files were changed between commits. I don’t want to deploy all files with each release so I wrote a small script that I use as a custom action in Sourcetree. It’s a batch script that takes 3 parameters:

  • the local path of the repository
  • hash of selected commit #1
  • hash of selected commit #2

sourcetree_git_diff_custom_action01

Batch script is added below, you’ll just need to modify the path to your local git.exe file
it contains a fix for windows users to replace the forward slash of git diff by a backslash

@echo off
setlocal EnableDelayedExpansion

C:\Users\<myusername>\AppData\Local\Atlassian\SourceTree\git_local\bin\git.exe diff --name-only %2 %3 > "C:\temp\a.txt"

mkdir C:\temp\%2
for /F "tokens=*" %%b in (c:\temp\a.txt) do (

set "lineString=%%b"
set "to_replace=/"
for %%f in ("!to_replace!") do set "str2=!lineString:%%~f=\!"
REM echo "%1\!str2!"

ECHO Processing "%1\!str2!" ....

xcopy "%1\!str2!" "C:\temp\%2\!str2!*" /s /i /Y
)

endlocal

Select the 2 commits and execute the custom action. The modified files will be copied under C:\temp\<hash1>\

sourcetree_git_diff_custom_action02