Git basics

See what changed before you commit (git diff)

Check exactly what you changed with git diff before you commit, so nothing goes in by mistake.

Fill these in once
  1. See what changed but isn't staged yet
    Terminal
    git diff

    Lines starting with + were added and lines starting with - were removed. Press q to leave.

  2. See what is staged and will go into the next commit
    Terminal
    git diff --staged
  3. See the changes in one file
    Terminal
    git diff -- src/app.js
  4. See only which files changed
    Terminal
    git diff --stat

    Shows each file with a count of lines added and removed, without the details.

Check it worked

  1. Check which files are staged and which aren't
    Terminal
    git status
Undo it
  1. Take a file back out of the next commit
    Terminal
    git restore --staged src/app.js

    Your changes stay in the file. They just won't go into the next commit until you add them again.

  1. See what changed but isn't staged yet
    Terminal · Ubuntu / Debian
    git diff

    Lines starting with + were added and lines starting with - were removed. Press q to leave.

  2. See what is staged and will go into the next commit
    Terminal · Ubuntu / Debian
    git diff --staged
  3. See the changes in one file
    Terminal · Ubuntu / Debian
    git diff -- src/app.js
  4. See only which files changed
    Terminal · Ubuntu / Debian
    git diff --stat

    Shows each file with a count of lines added and removed, without the details.

Check it worked

  1. Check which files are staged and which aren't
    Terminal · Ubuntu / Debian
    git status
Undo it
  1. Take a file back out of the next commit
    Terminal · Ubuntu / Debian
    git restore --staged src/app.js

    Your changes stay in the file. They just won't go into the next commit until you add them again.

  1. See what changed but isn't staged yet
    PowerShell
    git diff

    Lines starting with + were added and lines starting with - were removed. Press q to leave.

  2. See what is staged and will go into the next commit
    PowerShell
    git diff --staged
  3. See the changes in one file
    PowerShell
    git diff -- src/app.js
  4. See only which files changed
    PowerShell
    git diff --stat

    Shows each file with a count of lines added and removed, without the details.

Check it worked

  1. Check which files are staged and which aren't
    PowerShell
    git status
Undo it
  1. Take a file back out of the next commit
    PowerShell
    git restore --staged src/app.js

    Your changes stay in the file. They just won't go into the next commit until you add them again.

New to commit? I explain it in plain English on Layman Terms.