I'm trying to assign the last commit message inside a git repository to a variable in a windows batch script and then export the variable. From a lot of questions from StackOverflow, it seems that the command should be:
for /f "Tokens=2" %a in ('git log -1 --pretty=%B') do @set commit_message=%a
export %commit_message%
But it's giving the following error.
fatal: ambiguous argument '%B': unknown revision or path not in the working tree.
Use '--' to separate paths from revisions, like this:
'git <command> [<revision>...] -- [<file>...]'
In Linux it is quite straight forward. Only export commit_message=$(git log -1 --pretty=%B).
... %%X In ('git log -1 --pretty^=%%B') Do @Set "commit_message=%%X"or... %%X In ('"git log -1 --pretty=%%B"') Do @Set "commit_message=%%X".