Situation: You made a commit and later realise you changed a file or files you were not suppose to.
Sometimes after commit is made but before it is merged into master you want to restore a file or a number of files that were not suppose to be changed.
Undo last commit command:
git checkout origin/main -- CoolFeature/SpecialViewModel.swift
git commit -am "Restore SpecialViewModel.swift"
What does command do
In essence this command takes current version of a file from main branch
you are interested in and puts it back into your branch. You need to provide the full path to the file that you want to restore.
Keep in mind you still need to perform a commit and push it to remote.