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:

  1. git ls-files -v lists all files in my git workspace, prefixed with a single-letter flag.
  2. 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.
  3. xargs -n 1 runs the final git command once per line.
  4. git update-index --no-skip-worktree performs 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...

Who cares?

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.

More Posts