In this lesson, you will see several ways to use the commit history of Git to recover from problems you encounter when working with files in a project.
Learning objectives At the end of this lesson, the learner will be able to:
undo changes made to a file before it was added to a commit.
revert commits to return to a previous committed version.
resolve a version conflict between a locally edited file and a file on GitHub using Atom.
find an old version of a file using the version history and recover it from GitHub.
remove and reclone a repository to reverse changes made since the last push to GitHub.
If you want to discard the changes from more than on file, you can select several by holding on the command button (Mac) or Ctrl button (Windows), then clicking on the files you want to select, or clicking on the first file, then holding down the shift and clicking on the last file in a range of files. Then right-click and select Discard x Selected Changes.
Level 2: Reverting a bad commit (4m28s)
Level 2.5: Resolving a version conflict using Atom (4m00s)
Level 2.5: Recovering a deleted file using the file history (4m06s)
Level 3: Recloning the repository (3m57s)
Practice assignment
Edit and save a file without committing it. Then use GitHub Desktop to discard the changes.
Delete a previously committed file (but don’t commit that change). Use GitHub Desktop to recover it by “discarding” the deletion.
Make sure that all changes are committed. Then make some undesirable change to a file, commit that change, then revert that commit to restore the version to the previous commit. (Note: it does not matter whether you have pushed the commit to GitHub or not.)
Use the version history on GitHub Desktop to find the point in time when you revised a file to a particular version that you want to recover. View the diff online and then download the file from that version.
Make sure that all changes that you want are committed and pushed to GitHub. Make any number of changes and commits, but don’t push those commits to GitHub. Remove the repository using GitHub desktop. Then restore the older version of the repository (without the unpushed commits) by recloning it from GitHub.
Simulate a major disaster on your computer by just deleting an entire repository folder. In GitHub Desktop, try to switch to that repository. Can you figure out how to get it back?