Git

Last Updated: 7/28/2023

Restoring a File to an Earlier Version

  • Once Git tracks a file, it stores every version of that file in its database means if you screw things, we can always restore a file or a directory to a previous version
  • You can restore a file to a previous version, without undoing a commit.
  • By default, git will restore a file from the next environment or the next area. So if the file we want to restore is in the working directory gits we'll restore it from the staging area. And if the file is in the staging area, it will restore it from the last snapshot or the last commit.
git rm file1.txt
git commit -m "Delete file1.txt"

git restore --source=HEAD~1 file1.txt