Reputation: 281
I am working with jenkins and git. I want to get difference between current commit and the commit before current. I want to make this current and previous commit id;s to be generated at runtime. I am using this in batch file but it is not executing the git rev-parse commands and storing the hash id in prev_com and curr_com. Any help is appreciated.
cd "C:\Users\TF255014\Eclipse Projects Repo\Hello World"
set prev_com=${git rev-parse @~}
set curr_com=${git rev-parse HEAD}
echo %prev_com%
git diff %prev_com% %curr_com%
Upvotes: 3
Views: 7144
Reputation: 1
Just in case someone bumps on this thread...
following is a one liner for BAT:
for /f %%i in ('git.exe rev-parse @~') do set COMMIT_ID=%%i
Upvotes: 0
Reputation: 17999
Seems like you are mixing bash
and batch
scrips. If you are on Windows, you can assign the output of a command to a variable using 'temporary' files:
git rev-parse @~ > prev_com.txt
set /p prev_com=<prev_com.txt
git rev-parse HEAD > curr_com.txt
set /p curr_com=<curr_com.txt
or for loops:
for /f %%i in ('git rev-parse @~') do set prev_com=%%i
for /f %%i in ('git rev-parse HEAD') do set curr_com=%%i
The following would work in a bash
script:
prev_com=$(git rev-parse @~)
Apart from that, I don't think you need the two variables. You could simply run:
git show HEAD
or, to get the diff only:
git show --pretty= HEAD
Upvotes: 5