Step 1: Navigate to Your GitHub Repository
- Open your web browser and go to github.com.
- Log in with your GitHub credentials if you haven’t already.
- Click on your profile icon in the top-right corner and select Your repositories from the dropdown.
- Select the repository you wish to explore by clicking its name.
Step 2: Go to the Commits Tab
- Within your repository page, click on the “Code” tab if you’re not already there.
- Locate and click on the Commits link or button. It’s usually above the file list or next to the branch selector.
Step 3: Select a Specific Commit
- You will see a chronological list of commits, each showing a commit message, author, date, and a short SHA identifier.
- Click on the commit message or SHA hash of the commit you want to inspect.
Step 4: View the Diff for That Commit
- After clicking, the commit details page will load, showing changed files and the diff for each.
- In the diff view:
- Lines removed are highlighted in red with a “–” prefix.
- Lines added are highlighted in green with a “+” prefix.
- Scroll through the files to review all changes made in that commit.
Step 5: Filter and Search Within the Diff
- Above the list of changed files, use the Filter files box to type a filename or path to narrow down displayed diffs.
- Within an open diff, press Ctrl + F (or Cmd + F on macOS) to search for specific code snippets or keywords.
Step 6: Compare Two Branches, Tags, or Commits
- To compare branches or tags, click on the Compare button (often labeled “Compare & pull request”) near the branch selector.
- Select the base branch/tag and the compare branch/tag from the dropdowns.
- GitHub will display a combined diff between the two points.
Step 7: Compare Specific Commits Using a Direct URL
- You can construct a URL like this to compare two commit SHAs directly:
https://github.com/OWNER/REPO/compare/COMMIT_SHA1...COMMIT_SHA2
- Replace OWNER, REPO, and the SHA placeholders with your actual values.
Step 8: View Diffs Locally with Git (Optional)
- If you have the repository cloned locally, you can view diffs between commits using the command line:
git diff COMMIT_SHA1 COMMIT_SHA2
- This shows the same red/green diff output in your terminal.