Undo
Since Sapling keeps a full record of the mutation history of commits, most Sapling commands that modify commits can be easily undone. The sl undo
command will revert the commit graph to its state prior to the last run command.
$ sl
│ Commit Two
│
╭─╯ Commit One
│
╷
╷
~
# Change #1 to rename the commit.
$ sl metaedit -m "Commit Two Renamed"
# Change #2 to move the commit.
$ sl rebase -s 4eefdfe1d -d stable
$ sl
╷
╷
╷ │ Commit Two Renamed
╷ │
╷
╭─╯ Commit One
│
╷
~
# Undo change #2.
$ sl undo
$ sl
│ Commit Two Renamed
│
╭─╯ Commit One
│
╷
╷
~
Running the command again will undo the command run before the last undone command. Use the sl redo
command to reverse the undo command.
# Undo change #1.
$ sl undo
$ sl
│ Commit Two
│
╭─╯ Commit One
│
╷
~
# Oops! I didn't mean to undo that rename.
$ sl redo
$ sl
$ @ f5c155dd8 5 minutes ago mary
│ Commit Two Renamed
│
╭─╯ Commit One
│
╷
~
Undo --interactive
You can visualize the undo before it happens by using the sl undo -i
interactive command. This gives an interactive terminal UI where you can use the
left and right keyboard keys to view the previous states you can undo to.
Red commits are those that will be removed, while yellow are commits that will be
visible. Press enter
to confirm the rollback, or press q
to abort.
This UI is also useful for simply finding old commit hashes. Once you have the
hash, you can exit the undo UI, then use sl show HASH
and sl unhide HASH
to
view and recover the commit.
Uncommit / unamend
The undo command is limited to undoing changes to the commit graph. To undo changes related to the working copy, like a commit or amend, use sl uncommit
and sl unamend
.
$ sl
╭─╯ my feature
│
╷
~
$ echo "edit myproject.cpp" >> myproject.cpp
$ sl commit -m "new commit"
$ sl
│ new commit
│
╭─╯ my feature
│
╷
~
# Oops! I meant to amend my changes instead.
$ sl uncommit
╭─╯ my feature
│
╷
~
# Now we're back to the state prior to the commit.
$ sl st
M myproject.cpp
$ sl amend
$ sl
╭─╯ my feature
│
╷
~
# Now let's say we change our mind and decide to make a new
# commit after all. Let's undo the amend.
$ sl unamend
$ sl st
M myproject.cpp
# now the changes are back as pending changes in our working copy
You can limit uncommit to specific files by using sl uncommit FILE1 FILE2 ...
.