I was trying to quickly edit an
.hgignore file from the Cygwin bash shell today, and I added a line that was a mistake. I'm not sure if this was the best way to do it, but I quickly thought of using
head -1 .hgignore to remove the offending line (I had previously only had one line in the file). Sure enough, when executed it gives the first line as the only output.
But when I tried to redirect the output and rewrite the file using
head -1 .hgignore > .hgignore, the file was empty. Why does this happen? If I try appending instead,
head -1 .hgignore >> .hgignore, it appends correctly but this is obviously not the desired result. Why does a truncating redirect not work in this case?