繁体   English   中英

使用Powershell的Git命令

[英]Git Commands using powershell

如何将git的默认目录作为当前powershell脚本的位置

这是git-init.ps1的内容

C:/Users/MyUser/Desktop/Project101/git-init.ps1

我想初始化此路径C:/ Users / MyUser / Desktop / Project101 /

但问题是git会初始化此路径c:/Users/MyUser/.git我只是遵循了Git Bash的命令

任何帮助将不胜感激。 TIA

function run-git
{
    # location of my installed git
    $x = Get-ChildItem env:LOCALAPPDATA | %{ $_.Value }
    $y = $x + "\Programs\Git\bin\sh.exe"

    # .$y --login -i -c "git init"
    # .$y --login -i -c "git remote add -t 'master' 'origin' 'E:/ProjectRepository/Project101'"
    # .$y --login -i -c "git pull"

    # get the location of this script
    $Invocation = (Get-Variable MyInvocation -Scope 1).Value
    $p = Split-Path $Invocation.MyCommand.Path

    .$y --login -i -c "cd $p"
    .$y --login -i -c "git init"
    # .$y --login -i -c "git init 'E:/WorkingDirectory'"
    .$y --login -i -c "git status"
}

run-git;

问题是当您执行以下操作时:

.$y --login -i -c "cd $p"

您正在运行外壳程序,更改目录,然后退出外壳程序。 新位置丢失。

我建议使用

Push-Location $p

# Do git commands here, remember that git spews verbose on stderr and causes powershell to barf

Pop-Location

另一种选择是使用git --work-tree="$p"或类似的东西,但这就是疯狂。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM