Search code examples
gitpowershellstdin

'git am < MyFix.patch' command error in Powershell


How do we get this command to run on Powershell with out error : The '<' operator is reserved for future use.

C:\Users\Me\my-git-repo > git am < MyFix.patch
    The '<' operator is reserved for future use.
    At line:1 char:9
    + git am < <<<<  MyFix.patch
    + CategoryInfo          : ParserError: (<:OperatorToken) [],..      
    + FullyQualifiedErrorId : RedirectionNotSupported

Solution

  • Use either:

    Get-Content MyFix.patch | git am
    

    or:

    cmd /c 'git am < MyFix.patch'
    

    Both should work equally well. Windows Powershell simply doesn't support IO redirection with < for now, so you either need to pipe the text to stdin using | (Get-Content[1] sends the contents of MyFix.patch to stdout and | feeds it along to git am's stdin); alternatively, run the command through CMD.exe.


    [1] Alternatively, use the built-in alias type.