Skip to content

Instantly share code, notes, and snippets.

@tlrobinson
Last active December 13, 2021 00:00
Show Gist options
  • Save tlrobinson/6cad91b1203a7d2c174824a4d7814a42 to your computer and use it in GitHub Desktop.
Save tlrobinson/6cad91b1203a7d2c174824a4d7814a42 to your computer and use it in GitHub Desktop.
Steps for merging an old branch into a newly prettier-ified codebase. Use at your own risk, verify everything was correctly merged.
# Assumes 3 sequential commits:
#
# 1. commit tagged "prettier-before" that added `prettier` depedency and `prettier` script your package.json
# 2. commit that actually ran `prettier` on your entire codebase for the first time
# 3. commit tagged "prettier-after" that fixes any minor issues caused by prettier (e.x. moving eslint-ignore or $FlowFixMe comments around), or just the next commit if there were none
#
# I recommend running these as individual commands, not as a script, in case of merge conflicts
#
# Checkout the non-pretty branch you want to merge
# (or optionally make a new branch with `git checkout -b $YOUR_BRANCH-prettier $YOUR_BRANCH`)
git checkout $YOUR_BRANCH
# Merge the commit immediately prior to running prettier globally:
git merge prettier-before
# Manually resolve conflicts if necessary, then commit if necessary
# Save a list of changed files between that commit and your branch pre-prettier as a sanity check
git diff --name-only prettier-before > prettier-before.diff
# Update the dependencies and run `prettier` on your branch:
yarn
yarn run prettier
# Commit the results
git commit -a -m "Run prettier on $YOUR_BRANCH"
# Cherry-pick the commit after you ran prettier
git cherry-pick prettier-after
# Then merge with same commit
git merge -Xours prettier-after
# Save a list of changed files between that commit and your newly merged branch, then diff it with the previously saved list to make sure there aren't any unexpectedly changed files
git diff --name-only prettier-after > prettier-after.diff
diff prettier-before.diff prettier-after.diff
# Merge with master (or any commit after `prettier-after`):
git merge origin/master
# Run lint/flow/tests, if applicable
yarn run lint && yarn run flow && yarn run test
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment