Module 1
Commit History and Recovery
Section 1–1
Commit History
What is your Commit History?
• Your commit history is a chronological record of all the changes made to your project over time. Think of it as a detailed diary that automatically tracks every modification, addition, and deletion in your codebase.
- Each commit contains the complete state of all files at that moment.
- Commits are linked together, forming a chain of project history.
- You can see who changed what, when, and why.
- GitHub displays this history in a visual timeline.
- Green dots typically indicate additions, red indicates deletions.
- Commit messages should be clear and descriptive.
- History helps track down when bugs were introduced.
- Multiple developers can work simultaneously without conflicts.
You can click the "Commits" button to review all your commits.
This will allow you to review all your past commits and messages. This is why it is so important to write useful messages — this will help you find your past changes much faster.
If you click on a commit message, you will be shown the changes that occurred in that commit.
Section 1–2
Recovery
How can you recover your changes?
• When something goes wrong with your code, your commit history becomes your safety net. There are several ways to get back to a working state, depending on your situation and comfort level.
Manual Recovery
- Go to your commits and click revert changes.
- Navigate to your repository on GitHub.com.
- Click on the commit history (usually shows number of commits).
- Find the problematic commit.
- Click on the commit to view the changes.
- Use GitHub's "Revert" button to automatically undo that specific commit.
- This creates a new commit that undoes the problematic changes.
- Copy and paste old code by going through commits.
- Browse through your commit history to find when your code was working.
- Click on individual commits to see the file contents at that time.
- Open the files you need to fix in your current editor.
- Copy the working code from the historical commit.
- Paste it back into your current files.
- Make a new commit with your recovered code.
- This method gives you full control over what gets restored.
Advanced Recovery (requires further research)
Advanced techniques require command line and bash knowledge and can be powerful but potentially destructive if used incorrectly. They are worth researching once you're comfortable with basic Git concepts.
- Git Rebase Operations:
- Interactive rebase allows you to edit, reorder, or squash commits.
- Apply specific commits from one branch to another.
- Move your branch pointer to a different commit.
- You can use reflog to access commits that aren't visible in normal history.