-
-
Notifications
You must be signed in to change notification settings - Fork 90
Command: git undo
Available since v0.1.0.
git undo
is an undo command which can undo any operation to the commit graph, such as the following:
- Commits.
- Amended commits.
- Merges and rebases (such as if you merged something wrongly and want to try again).
- Checkouts.
- Branch renames, moves, and deletions.
git undo
offers a convenient visual interface to browse previous states of the repository and go back in time. See the demo below:
Operations other than those to the commit graph, such as operations which affect the working copy, can't be undone with git undo
.
See What can't git undo
do?, and check the Undo reference table for another solution to your problem. You can also start a new discussion to ask questions.
By default, git undo
will offer to undo the last operation. Adding -i/--interactive
will make it an interactive program which shows you the previous states of the repository. See the demo for an example.
Use the arrow keys to move forward or backward in time, and find the version of the commit graph you want. Then press enter, and it will show you a list of operations to carry out, which you can either accept or reject:
$ git undo
...select previous state interactively...
Will apply these actions:
1. Hide commit 8d4738cd new message
Confirm? [yN] y
Applied 1 inverse event.
git undo
is responsible for editing the commit graph. In git-branchless
v0.4.0 or later, it can also undo changes to the working copy as long as they were captured in a snapshot, which are created by some git-branchless
commands.
Changes to untracked files cannot be undone with git undo
.
See the reference table below.
Here are some topics from https://www.git-tower.com/blog/surviving-with-git-videos/, and whether they can be accomplished with git-branchless
. The goal is to make most of these effortless with future work.
Problem | Solution | Planned for git-branchless ? |
Proposed command |
---|---|---|---|
#1 Discarding All Local Changes in a File | git restore |
No | |
#2 Restoring a Deleted File |
git undo (if snapshot exists) |
— | |
#3 Discarding Chunks / Lines in a File | git add -p |
Yes | git record |
#4 Discarding All Local Changes | git restore |
No | |
#5 Fixing the Last Commit |
git amend /git reword
|
— | |
#6 Reverting a Commit in the Middle | git rebase -i |
Yes | git adjust |
#7 Resetting to an Old Revision | git undo |
— | |
#8 Resetting a File to an Old Revision | git restore |
No | |
#9 Recovering Deleted Commits | git undo |
— | |
#10 Recovering a Deleted Branch | git undo |
— | |
#11 Moving a Commit to a New Branch | git move |
— | |
#12 Moving a Commit to a Different Branch | git move |
— | |
#13 Editing Old Commit Messages | git reword |
— | |
#14 Deleting Old Commits | git rebase -i |
Yes | git adjust |
#15 Squashing Multiple Commits Into One | git rebase -i |
Yes | git adjust |
#16 Adding a Change to an Old Commit | git amend |
— | |
#17 Splitting / Editing an Old Commit | git rebase -i |
Yes | git split |
- Search the Wiki 🔎
- User guide
- Welcome
- Installation
- Tutorial
- Command overview
- General:
- Navigation:
- Committing:
- Rebasing:
- Verification:
- Collaboration:
- Workflows
- Advanced topics
- Reference
- Developer guide
- Onboarding offer
- Development
- Reference