Checking the status, differences, logs & restore

Git - Quick Reference

3 min read

Published Jun 19 2025


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.


Products from our shop

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet - Print at Home Designs

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Mouse Mat

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Travel Mug

Docker Cheat Sheet Mug

Docker Cheat Sheet Mug

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet - Print at Home Designs

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Mouse Mat

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Travel Mug

Vim Cheat Sheet Mug

Vim Cheat Sheet Mug

SimpleSteps.guide branded Travel Mug

SimpleSteps.guide branded Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript - Travel Mug

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Dark

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Embroidered T-Shirt - Light

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - White

Developer Excuse Javascript Mug - Black

Developer Excuse Javascript Mug - Black

SimpleSteps.guide branded stainless steel water bottle

SimpleSteps.guide branded stainless steel water bottle

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Light

Developer Excuse Javascript Hoodie - Dark

Developer Excuse Javascript Hoodie - Dark

© 2025 SimpleSteps.guide
AboutFAQPoliciesContact