" to discard changes in the working directory) (use "git push" to publish your local commits) Your branch is ahead of 'origin/master' by 3 commits. Keep this in mind and use the git checkout command, preferably GitProtect, if necessary. This means that we can, for example, undelete deleted files from the local disk from the repository, but not files in the repository itself. The name can be confusing, too, as using git restore is not used to undo changes to a repository but to undo local changes to a local disk. Still, you have to remember that even the official Git documentation (can be found here) says that this tool is experimental, and you should never forget that. Another exciting command that we can use is git restore.
We must also remember that the git checkout command is not the only built-in tool in Git that will allow us to restore changes, files, etc. Listing 1.Finding and restoring files with the git checkout command. # We will restore to the last version of the file here. # We need to find here a change that interests us. Here’s a little mystery, does this command work on deleted files with the git rm command? The truth is, however, that we don’t have to worry about such questions anymore because GitProtect is on the horizon! $ git init You should also remember that we can restore with the command git ls-files -d | xargs git checkout - files in a given folder. Thanks to this, we can find and select the most appropriate version, but it should be noted that we have to choose the correct change ourselves using the git log and git diff commands. In the first and third approaches, we have to choose which commit is the target commit at some point. The script presents various approaches to search for a change of interest and use the git checkout command.
In the case of Git, we know that we have the git checkout command at our disposal, and thanks to it, we can restore the file to the desired state using the script presented in Listing 1.