When I go to the build directory of my application, and I ask for the commit hash, everything is working fine:
Prompt>git log -1 --format=format:"%H"
c03245bcdf6ddd7b54af4c70d9012e16a6c8c64f
When I try this in a post-build event (Visual Studio, C# application), this does not work:
Post-build event:
git log -1 --format=format:"%H" >Release_Note2.txt
Contents of the file "Release_Note2.txt:
H
(indeed, just one single letter)
Does anybody know what I can do in order to get the commit hash of my application in a post-build event of my application?
I'm working on a Windows machine.
To get the current commit:
git rev-parse HEADThat will print the current commit ID your
HEADis pointing to. You can substituteHEADwith any tag or branch you'd like to know as well. (And also@in most shells is a shorthand forHEAD.)As for why your attempt didn't work, my guess is that maybe your string needs to be escaped inside of your C# application, e.g.:
git log -1 --format=format:\"%H\" >Release_Note2.txtThough, if you switch to the preferred
rev-parsecommand perhaps you don't need to worry about why.