Back

TIL: How to reset all files in one folder in git

We use snapshot testing at work quite heavily because it enables us to test the output of complex functions that do a lot of things at the same time and produce a lot of output.

During a PR, I often accumulate a lot of files in one folder and when the PR is done, I want to clean up this folder, reset it to the state of the development branch, and re-create just the files I need.

To reset a whole folder to the state of this folder on another branch in git, you can do:

git restore --source=develop --staged --worktree tests/data

This resets the tests/data folder to the state of that folder on the develop branch.