Git 2 cheatsheet

Git 2: Committing

8 common Git 2 tasks.

Stage all changes

Stage every modified, new and deleted file in the current directory and below.

git add .

Stage parts of a file

Choose which hunks of a file to stage.

git add -p

Commit staged changes

Record the staged changes with a message.

git commit -m "Add login form"

Change the last commit message

Replace the message of the most recent commit.

git commit --amend -m "New message"

Caution: This rewrites the commit. Avoid it once the commit has been pushed and shared.

See unstaged changes

Show what changed since the last stage or commit.

git diff

See staged changes

Show what will go into the next commit.

git diff --staged

View history compactly

Show one line per commit with the branch graph.

git log --oneline --graph --decorate

Show a commit

Show the message and changes of the latest commit.

git show HEAD

Was this page helpful?