


An example of using the git revert command.īeyond git revert and co. Hint: Waiting for your editor to close the file.ġ file changed, 0 insertions(+), 0 deletions(-)Ĭommit 06724135d660b9afbde334e61f98113349b52f48 (HEAD -> master) This approach is mentioned as one of the best practices in creating projects.

This approach is very desirable and very similar to supporting Electronic Document Management (EDM), one of the main assumptions of complete transparency about changes in documents. Thanks to this, we can keep documentation and information about our project according to actual events. It is thanks to this property that this command is used very often. This means that it can make a git restore of the changes from a given git commit and at the same time make a new git commit informing about this event. Using the git restore command to restore a local file from a repository.Īnother interesting tool is git revert, which will allow us to undo the changes and leave a note about them. " 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. 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 says that this tool is experimental, and you should never forget that. 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, undo things or modified file, etc.Īnother exciting command that we can use is git restore. Git checkout and git restore – a quick introduction 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 DevOps backup is there to solve it for us! $ 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 specific commit is the target commit at some point. The script presents various approaches to searching for a change of interest and uses 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 specific file to the desired state using the script presented in Listing 1.
GIT REMOVE NEW FILES HOW TO
How to git revert file to previous commit
