The second-order-diff Git trick

submited by
Style Pass
2024-10-20 23:30:04

git status # verify that we're starting w/ a clean slate # Iteration 1: take an educated guess at a good sledgehammer # 1. Try out the candidate sledgehammer git grep -lF '":' -- posts | xargs perl -i -pe's{"(.+?)":([^.,:\s]+)}{[$1]($2)}g' # 2. Review results and judge git diff # => judgment: not right # 3. Roll back to clean slate in preparation for the next attempt git checkout -- posts # (also could have used git reset --hard)

# Iteration 2: refine the sledgehammer git grep -lF '":' -- posts | xargs perl -i -pe's{"(.+?)":([^.,!\)\]\s]+)}{[$1]($2)}g' git diff # => judgment: still not right git checkout -- posts # Iteration 3: refine the sledgehammer more git grep -lF '":' -- posts | xargs perl -i -pe's{"(.+?)":([^,!\)\]\s]+)\b}{[$1]($2)}g' git diff # => judgment: still not right git checkout -- posts

Leave a Comment