Skip to main content
wit provides powerful commands for modifying commit history. Use these carefully - some operations can permanently alter your repository’s history.

Overview

CommandEffectSafe for shared branches?
revertCreates new commit that undoes changesYes
resetMoves branch pointer, optionally changes filesNo
cherry-pickCopies commits to current branchYes
rebaseReplays commits onto different baseNo

Revert

Create a new commit that undoes the changes from a previous commit. This is the safest way to undo changes on shared branches.
# Revert a single commit
wit revert <commit>

# Revert multiple commits
wit revert <commit1> <commit2>

# Revert without creating a commit (stage changes only)
wit revert -n <commit>

# Revert a merge commit (specify parent)
wit revert -m 1 <merge-commit>

Options

OptionDescription
-n, --no-commitStage the reverted changes without committing
-m, --mainline <n>For merge commits, specify which parent (1 or 2)
-s, --signoffAdd Signed-off-by line to commit message
--continueContinue after resolving conflicts
--abortAbort the revert operation
--skipSkip current commit and continue

Examples

# Revert the last commit
wit revert HEAD

# Output:
# ✓ Revert completed: 1 commit(s) created
#   abc1234

# Revert a specific commit
wit revert abc1234

# Revert multiple commits (creates one revert commit per original)
wit revert abc1234 def5678

# Revert a merge commit
wit revert -m 1 abc1234

Handling Conflicts

# If revert causes conflicts:
wit revert abc1234
# error: Revert stopped due to conflicts in 2 file(s)
# 
# Conflicts in:
#   src/file1.ts
#   src/file2.ts

# Resolve conflicts, then continue
wit add src/file1.ts src/file2.ts
wit revert --continue

# Or abort the revert
wit revert --abort

Reset

Move the current branch pointer to a different commit. This can also modify the staging area and working directory.
# Undo commit, keep changes staged
wit reset --soft HEAD~1

# Undo commit, keep changes unstaged (default)
wit reset --mixed HEAD~1

# Undo commit, discard all changes
wit reset --hard HEAD~1

# Unstage a file
wit reset <file>

Reset Modes

ModeHEADIndex (Staging)Working Directory
--softMovedUnchangedUnchanged
--mixed (default)MovedResetUnchanged
--hardMovedResetReset

Revision Syntax

# Go back 1 commit
wit reset HEAD~1
wit reset HEAD^

# Go back 3 commits
wit reset HEAD~3
wit reset HEAD^^^

# Reset to specific commit
wit reset abc1234

# Reset to branch
wit reset origin/main

Examples

# Undo last commit but keep changes staged (ready to recommit)
wit reset --soft HEAD~1
# ✓ Reset soft to abc1234
#   Was: def5678
# Your changes are still staged.

# Undo last commit, unstage changes (for editing before recommit)
wit reset HEAD~1
# ✓ Reset mixed to abc1234
#   Was: def5678
# Your changes are preserved but unstaged.

# Completely discard last 3 commits
wit reset --hard HEAD~3
# ✓ Reset hard to abc1234
#   Was: def5678
# Working directory has been reset.

# Unstage a file
wit reset src/file.ts
# Unstaged: src/file.ts
Danger Zone: wit reset --hard discards changes permanently. Always double-check before using it. Consider wit snapshot first.

Recovering from Hard Reset

# If you accidentally reset --hard, use undo
wit undo

# Or check the reflog
wit reflog
wit reset --hard <previous-hash>

Cherry-pick

Apply changes from specific commits to the current branch.
# Apply a single commit
wit cherry-pick <commit>

# Apply multiple commits
wit cherry-pick <commit1> <commit2> <commit3>

# Apply without committing
wit cherry-pick -n <commit>

# Continue after resolving conflicts
wit cherry-pick --continue

# Abort cherry-pick
wit cherry-pick --abort

# Skip current commit
wit cherry-pick --skip

Options

OptionDescription
-n, --no-commitApply changes without creating a commit
-s, --signoffAdd Signed-off-by line
--continueContinue after resolving conflicts
--abortAbort the operation
--skipSkip current commit and continue

Examples

# Cherry-pick a bug fix from another branch
wit cherry-pick abc1234

# Output:
# ✓ Cherry-pick completed: 1 commit(s) applied
#   def5678

# Cherry-pick multiple commits
wit cherry-pick abc1234 def5678 ghi9012

# Cherry-pick without committing (combine multiple picks)
wit cherry-pick -n abc1234
wit cherry-pick -n def5678
wit commit -m "Combined cherry-picks"

Handling Conflicts

# If cherry-pick causes conflicts:
wit cherry-pick abc1234
# error: Cherry-pick stopped due to conflicts in 1 file(s)

# Resolve conflicts
# Edit the conflicted files
wit add resolved-file.ts
wit cherry-pick --continue

# Or skip this commit
wit cherry-pick --skip

# Or abort entirely
wit cherry-pick --abort

Use Cases

# On main branch, get the fix commit hash
wit log --oneline
# abc1234 Fix security vulnerability

# Switch to release branch
wit switch release-1.0

# Apply the fix
wit cherry-pick abc1234
# Pick specific commits from feature branch to main
wit switch main
wit cherry-pick feature~3  # Third commit from tip
wit cherry-pick feature~2  # Second commit from tip

Rebase

Reapply commits on top of another base commit. This creates a linear history.
# Rebase current branch onto main
wit rebase main

# Rebase onto a specific commit
wit rebase <commit>

# Interactive rebase (coming soon)
wit rebase -i HEAD~3

# Continue after resolving conflicts
wit rebase --continue

# Abort rebase
wit rebase --abort

# Skip current commit
wit rebase --skip

Options

OptionDescription
--onto <newbase>Rebase onto a different base
--continueContinue after resolving conflicts
--abortAbort and restore original branch
--skipSkip current commit

How Rebase Works

Before rebase:
      A---B---C  (feature)
     /
D---E---F---G  (main)

After `wit rebase main`:
              A'--B'--C'  (feature)
             /
D---E---F---G  (main)

Examples

# Update feature branch with latest main
wit switch feature
wit rebase main

# Output:
# Rebasing feature onto main...
# ✓ Successfully rebased 3 commits

# If conflicts occur:
# Resolve conflicts in the file
wit add resolved-file.ts
wit rebase --continue
Never rebase shared branches: Rebasing rewrites commit history. If others have based work on your commits, rebasing will cause problems. Only rebase local, unpushed commits.

Comparison: When to Use What

ScenarioCommandWhy
Undo a pushed commitrevertCreates new history, safe for shared branches
Undo local commitsresetCleaner history, commits not shared yet
Copy a fix to another branchcherry-pickApplies specific changes without merging
Update feature branchrebase or mergeRebase for linear history, merge to preserve history
Combine recent commitsreset --soft then commitSquash without interactive rebase

Safety Tips

Create a backup first

wit snapshot create "before rebase"
wit rebase main

Check reflog for recovery

wit reflog
wit reset --hard HEAD@{2}

Use wit undo

# Many operations can be undone
wit undo

Don't rewrite shared history

Only rebase/reset commits that haven’t been pushed.