Checking the status, differences, logs & restore
Git - Quick Reference
3 min read
Published Jun 19 2025, updated Aug 17 2026
Guide Sections
Guide Comments
Checking the current status
You can check the current status at any time:
git statusThis tells you:
- Which branch you are on.
- Whether your branch is ahead/behind the remote branch.
- Which files are:
- Untracked - new files not added yet.
- Modified but not staged - ones you have changed but not added yet with
git add - Staged - added with
git add, but not committed yet. - Deleted - file deleted, either staged or not.
There is a short format, less verbose version too:
git status -sChecking the difference between two states
To see the difference between the current changes and what has already been staged:
git diffShows the unstaged changes.
To see the staged changes that will go in the next commit:
git diff --cachedShows the differences between the staged version and the last commit, so shows you what will be in the next commit.
Compare two commits:
git diff commit1 commit2Use the commit ids for the two commits to check.
Compare branches:
git diff develop my-other-branchWill compare the my-other-branch and develop branches.
Compare current working directory to a branch:
git diff mainWill compare current project files to main branch.
All the above will show a file with the following info:
+- added lines.-- removed lines.@@- meta data showing the line numbers.
Commit history
To view the history of commits on your repository:
git logThis tells you:
- When the change was made.
- Who made the change.
- The commit message of what the change contained.
Compact history of just hashes and messages:
git log --onelineShow branches and visual history:
git log --graph --oneline --allInclude the diff output of each commit:
git log -pUndo uncommited changes
You have edited a file but want to discard the changes:
git restore filenameYou staged a file and want to unstage it:
git restore --staged filenameYou want to undo both staged and working changes:
git restore --source=HEAD --staged --worktree filenameHow this option works:
- If the file already existed - revert to how it was at last commit.
- If the file is new - deletes the file from the working directory and the staged area.
You can add the --dry-run flag to the git restore command to see what Git will actually do, without doing it.
Git reset - more destructive undoing
This option is a lot more powerful and can be dangerous and destructive, so use with caution.
Undo a commit but keep your changes staged:
git reset --soft HEAD~1This moves the branch pointer back one commit, but your changes are still staged, ready to commit.
Unstage files - ( like git restore --staged )
git reset filenameLeaves the working directory untouched, just removes the file from staging.
Fully reset to a previous commit:
git reset --hard HEAD~1Moves the HEAD back one commit, erases all staged and working directory changes.