【问题标题】:CONVERT: GIT SHELL to GIT BATCH script转换:GIT SHELL 到 GIT BATCH 脚本
【发布时间】:2015-10-30 06:40:50
【问题描述】:

我需要一些帮助,因为我还想在 Windows 中运行它,所以我如何才能将这段代码从 shell 脚本编辑为批处理脚本。

 #!/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

我试过这个,但它给了我一个输出 "H" 而不是 "9b027aaccb996ae4895e4dfb428c5e6e24870e68"

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

【问题讨论】:

  • 我试过这个但它给了我一个输出 "H" @echo off SET commit_limit=4 git show HEAD~%commit_limit% --pretty=format:"%H" --no-patch pause
  • 我试过这个,但它给了我一个输出“H”而不是“9b027aaccb996ae4895e4dfb428c5e6e24870e68” >>> SET commit_limit=4 git show HEAD~%commit_limit% --pretty=format:"%H" - -无补丁暂停
  • 批处理文件不起作用,但可以在 cmd 中使用以下命令: git show HEAD~4 --pretty=format:"%H" --no-patch
  • 在批处理文件中尝试"%%H"

标签: windows shell batch-file ubuntu


【解决方案1】:
  • 在变量中,您必须使用双百分号转义百分号 (%) (%%)。
  • del 命令中将/ 替换为\
  • $branch 是一个 壳变量。我修复了批处理语法%branch%,你必须编辑 这个变量。

@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%

进一步阅读:

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-11-28
    • 2011-11-13
    • 2018-04-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-12-10
    • 1970-01-01
    相关资源
    最近更新 更多