Skip to content

Instantly share code, notes, and snippets.

@richardpringle
Created April 21, 2020 20:32
Show Gist options
  • Save richardpringle/967219d7f174606b5f5d3705e8d142c3 to your computer and use it in GitHub Desktop.
Save richardpringle/967219d7f174606b5f5d3705e8d142c3 to your computer and use it in GitHub Desktop.
File Isolation with git while debugging
# I've just refactored a bunch of my code, changing 2 files
$ run tests
# one test is broken, time to isolate
$ git add . && git commit -m WIP # commit my files
$ WIP=$(git rev-parse --short HEAD) # save the commit hash
$ git reset --hard HEAD~1 # reset my branch to the last known working state
$ git checkout $WIP -- file_1 # see if this file cause the issue
$ run tests
# tests pass, must be a different file
# time to reset file_1 and checkout file_2
$ git checkout HEAD -- . && git checkout $WIP -- file_2
$ run tests # hooray, I found the failure!
# ... now I can reset my branch, make the fix, and rebase my branch
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment