Commits are at the heart of Git – but creating them is only the beginning. Git gives you several ways to clean up, move, combine, undo, or reuse commits. Here are the most important ones and what they actually do.

First I start with one of my favorit features to work with commits - especially when I create plenty of small commits - and I really mean a lot of them ;)

Squash

Squashing combines multiple commits into one.

Before:

A -- B -- C -- D
          ↑    ↑
       fix 1  fix 2

After squashing:

A -- B -- E
          ↑
      complete fix

This is useful when several small commits actually belong to one logical change.

For example:

Add new page
Fix typo
Fix spacing
Fix typo again

could become:

Add new page

Remember: Squashing rewrites history. The new combined commit gets a new commit ID.

Squash = Turn several commits into one clean commit.

Rebase

Rebase takes your commits and puts them on top of another branch’s latest commit.

Before:

      D -- E  feature
     /
A -- B -- C  main

After rebasing the feature branch onto main:

A -- B -- C -- D' -- E'
          main          feature

Git recreates D and E on top of C. That’s why they become D’ and E’ – they are new commits with new IDs.

This is useful when main has moved forward while you were working and you want your feature branch to be based on the latest version.

Rebase = Take my commits and put them on top of this branch.

SmartGit tip: Checkout the branch you want to rebase first. Then select the branch you want to rebase it onto.

Reset

Reset moves your branch to another commit.

Before:

A -- B -- C -- D
               ↑
            feature

Reset the branch to B:

A -- B -- C -- D
     ↑
  feature

The important difference to Rebase: Git does not move or recreate your commits. It simply changes where the branch points.

Reset = Make my branch point to this commit.

Depending on the Reset mode, your changes can either be kept or discarded:

  • Soft → keep the changes staged
  • Mixed → keep the changes, but unstage them
  • Hard → discard the changes

⚠️ Be especially careful with Hard Reset, because local changes can be lost.

Rebase vs. Reset

These two are easy to confuse, but the basic difference is simple:

Rebase Reset
Moves/replays commits Moves the branch pointer
Keeps your work and puts it onto a new base Makes the branch point to another commit
Creates new commit IDs Does not create new commits
Useful to update a feature branch Useful to move a branch back or to another commit

The easiest way to remember it

Rebase:

“Put my commits on top of this.”

Reset:

“Move my branch here.”

Merge

A merge combines two development histories.

      D -- E
     /      \
A -- B -- C -- M

M is the new merge commit connecting the two histories.

Unlike Rebase, Merge doesn’t recreate your existing commits. Instead, it preserves the branches and joins them.

Merge = Combine two histories.

Rebase vs. Merge

Rebase:

A -- B -- C -- D' -- E'

Creates a clean, linear history.

Merge:

      D -- E
     /      \
A -- B -- C -- M

Preserves the branching history.

Neither is always better. Which one to use depends on your team’s Git workflow.

Amend

Amend lets you change your most recent commit.

For example, you can:

  • change the commit message
  • add a forgotten file
  • correct something in the commit

Amend = Fix my last commit instead of creating another one.

Remember: Amend creates a new commit ID. If the original commit has already been pushed, you may need to force-push the changed history.

Revert

Revert undoes a commit by creating a new commit that reverses its changes.

Before:

A -- B -- C

After reverting C:

A -- B -- C -- R

C stays in the history. R reverses its changes.

Revert = Undo a commit without deleting history.

This makes Revert useful for commits that have already been shared or pushed.

Another One of My Favorit: Cherry-Pick

Cherry-pick takes one specific commit from another branch and applies it to your current branch.

feature-a:  A -- B -- C
                      ↑
                  I want this

feature-b:  A -- D

After cherry-picking C:

feature-b:  A -- D -- C'

You don’t need the whole branch – just that one change.

Cherry-pick = Give me this commit, not the whole branch.

Quick Reminder

Action Think of it as…
Squash Combine my commits
Rebase Put my commits on top of this
Reset Move my branch here
Merge Combine two histories
Amend Fix my last commit
Revert Undo a commit safely
Cherry-Pick Take this one commit