Checking the status, differences, logs & restore

Git - Quick Reference

3 min read

Published Jun 19 2025, updated Aug 17 2026


7
0
0
0

CLIGit

Checking the current status

You can check the current status at any time:

git status

This 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 -s



Checking the difference between two states

To see the difference between the current changes and what has already been staged:

git diff

Shows the unstaged changes.


To see the staged changes that will go in the next commit:

git diff --cached

Shows 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 commit2

Use the commit ids for the two commits to check.


Compare branches:

git diff develop my-other-branch

Will compare the my-other-branch and develop branches.


Compare current working directory to a branch:

git diff main

Will 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 log

This 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 --oneline

Show branches and visual history:

git log --graph --oneline --all

Include the diff output of each commit:

git log -p



Undo uncommited changes

You have edited a file but want to discard the changes:

git restore filename

You staged a file and want to unstage it:

git restore --staged filename

You want to undo both staged and working changes:

git restore --source=HEAD --staged --worktree filename

How 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~1

This moves the branch pointer back one commit, but your changes are still staged, ready to commit.


Unstage files - ( like git restore --staged )

git reset filename

Leaves the working directory untouched, just removes the file from staging.


Fully reset to a previous commit:

git reset --hard HEAD~1

Moves the HEAD back one commit, erases all staged and working directory changes.

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact
Git - Quick Reference | Checking the status, differences, logs & restore | SimpleSteps.guide