0

I need some help how can I edited this code from a shell script to batch script, since i want to run it also in windows.

 #!/bin/bash
 commit_limit='4'
 log=`git show HEAD~$commit_limit --pretty=format:"%H" --no-patch`

 echo $log > .git/info/grafts
 git filter-branch -f -- --all
 rm .git/info/grafts
 git update-ref -d refs/original/refs/heads/master  
 git reflog expire --expire=now --all
 git gc --force --prune=now --aggressive
 git push --force origin $branch

i tried this but it give me an output "H" instead of "9b027aaccb996ae4895e4dfb428c5e6e24870e68"

SET commit_limit=4
git show HEAD~%commit_limit% --pretty=format:"%H" --no-patch
pause
4
  • i tried this but it give me an output "H" @echo off SET commit_limit=4 git show HEAD~%commit_limit% --pretty=format:"%H" --no-patch pause Commented Oct 30, 2015 at 6:46
  • i tried this but it give me an output "H" instead of "9b027aaccb996ae4895e4dfb428c5e6e24870e68" >>> SET commit_limit=4 git show HEAD~%commit_limit% --pretty=format:"%H" --no-patch pause Commented Oct 30, 2015 at 6:49
  • Batch File does not work but works in cmd with this command: git show HEAD~4 --pretty=format:"%H" --no-patch Commented Oct 30, 2015 at 7:02
  • 1
    Try "%%H" in batch file. Commented Oct 30, 2015 at 11:05

1 Answer 1

1
  • In variable you have to escape percent sign (%) with double percent (%%).
  • replaced / with \ in del command.
  • $branch is a shell variable. I fixed to batch syntax %branch%, you have to edit this variable.

@echo off

setlocal
rem edit branch variable
set "branch=branch"

set "commit_limit=4"
set "log=git show HEAD~%%commit_limit%% --pretty=format:"%%H" --no-patch"

%log% > .git\info\grafts

git filter-branch -f -- --all
del .git\info\grafts
git update-ref -d refs/original/refs/heads/master  
git reflog expire --expire=now --all
git gc --force --prune=now --aggressive
git push --force origin %branch%

Further reading:

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.