shellremoving-whitespace

Why does `git stripspace` delete all text?


I'm trying to run git stripspace but the documentation is not helpfull.

It appears that git stripspaces takes stdin as its input and writes to stdout but:

% git stripspace < myfile.txt > myfile.txt

deleted all the text in myfile.txt

I wish the documentation provided an invocation example. Does anyone have one?


Solution

  • The problem here is that you're redirecting from and to the same file. It wasn't GIT that did it. When you redirect stdout to a file, it first creates that file. Which in your case, created it empty (in other words, it overwrote your file).

    Try changing your simple command, which is this:

    git stripspace < myfile.txt > myfile.txt
    

    to this:

    git stripspace < myfile.txt > my-other-file.txt
    

    and it should work just fine.