Home > other >  How to escape percent symbol when using it as a command in a FOR loop?
How to escape percent symbol when using it as a command in a FOR loop?

Time:05-12

I'm trying to use de git log command result as input to for loop, but seems impossible! I already tried to use %%, ^%, %%%, ^%^%, enableDelayedExpansion and others:

@echo off
for /f %%s in ('git log --reverse --format=%h') do (
  echo git pull
  echo git reset --hard %%s
  pause
)

The git command I need is: git log --reverse --format=%h

The problem is that "%h" is not working inner the for. When I use git log --reverse, for example, it works.

CodePudding user response:

for /f %%s in ('git log --reverse --format^=%%h') do (

should cure your problem.

CodePudding user response:

You could define a format variable

set "format=--format=%%h"
for /f %%s in ('git log --reverse %%format%%') do (
  • Related