Reapplying commits when Git goes wrong

Sometimes work can get lost when there are mishaps using Git. Changes can be reversed by accident by reverts of merge commits for example.

The quickest way to fix such issues of lost changes is to use git cherry-pick which allows you to apply the changes introduced by existing commits.

git cherry-pick <commit> 

As a measure to prevent such issues it can be helpful to configure git to always perform a rebase on git pull rather than the default merge. This will prevent unnecessary merge commits.

git config --global pull.rebase true