'Windows batch file command formatting with usebackq
I'm trying to assign the results of a git command to a variable in a Windows batch file.
The line in question looks like:
FOR /F "USEBACKQ tokens=*" %%i IN (`git rev-parse --short=12 trunk`) DO set IMAGE_NAME=buildroot-buildenv-%%i
When I run this I get fatal: Needed a single revision, I assume because there is a command formatting issue with the --short=12 part of the command. (If I simply run git rev-parse trunk as the command, everything works fine)
How can I add the --short=12 option to the git command and get the proper result?
Solution 1:[1]
As noted in the comment by Magoo
You need to escape the
=in the git command with a caret (^=12not=12)
Solved it for me
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
