Perfectly Imperfect Bash
A quick and
dirty nerdy reflection on some Perfectly Imperfect Bash I just wrote while exploring the skip-worktree flag in Git:
git ls-files -v | grep 'S ' | xargs -n 1 git update-index --no-skip-worktree
To the uninitiated:
git ls-files -vlists all files in my git workspace, prefixed with a single-letter flag.
grep 'S 'filters based on those flags, looking for any file prefixed with an
S. I've been messing with these files, and want to revert that flag.
xargs -n 1runs the final git command once per line.
git update-index --no-skip-worktreeperforms the actual work of resetting the errant flag.
That boldfaced word in part 3 is the crux of my reflection. Part 4 would actually receive two arguments: the flag and the file itself. Upon brief reflection I asked an all-important question for engineers to ask: "Who cares?" I realized Git would attempt to interact with a file named
S, complaining at its non-existence but continuing with the real file anyway. I could spend the additional few minutes doing it the Right Way, but...
Maybe you do. Maybe you find it irresponsible that I'd make Git complain so much. If that sounds like you, here's your solution.
git ls-files -v | grep 'S ' | xargs -n 1 git update-index --no-skip-worktree 2> /dev/null
You're welcome. Go forth and keep shipping.
9th of June, 2014