You can use git stash to “roll back” changes for a while, and then when you want to restore your previous changes, use git stash pop *
You can also (and safer) do WIP work (work in progress), switch to another branch, do your work, return to the original branch, complete the original work, and then squash , your commit is only one.
Remember that commit is not equal to pushing, so you can have a dirty history locally, but after reinstalling and crushing you (and your team) will see only a clean version.
* note, because if you delay more than once, git pop will only show the last cache. In this case, you need to use git pop stash@ {<revision>}
source share