LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

git-undo

Undo recent commits while preserving changes

TLDR

Undo last commit
$ git undo
copy
Undo N commits
$ git undo [3]
copy
Undo and keep changes staged
$ git undo --soft
copy
Undo and discard changes
$ git undo --hard
copy

SYNOPSIS

git undo [count] [options]

DESCRIPTION

git undo removes the last commit(s) while keeping changes in the working directory (unstaged). It is a convenient wrapper around `git reset` that defaults to a mixed reset, preserving all work.Without arguments, it undoes the most recent commit. Pass a number to undo multiple commits. Use --soft to keep changes staged, or --hard to discard them entirely.

PARAMETERS

COUNT

Number of commits to undo (default: 1).
--soft
Keep changes staged.
--hard
Discard all changes.
--help
Display help information.

CAVEATS

Part of the git-extras package and must be installed separately. Only affects local commits that have not been pushed. --hard discards changes permanently and cannot be easily recovered.

SEE ALSO

Copied to clipboard
Kai