I created these small git commands to help make exploring commits and editing them easier.
The first set of commands, git uc
(Undo Commit) and git rc
(Redo Commit), will undo a commit while saving the commit message and keeping the changes staged, so you can make changes to the commit and re-perform the commit while having the original commit message restored. Example:
$ git uc
...make edits to staged changes...
$ git rc
...update commit message, original one is loaded into editor...
git rc
accepts any additional arguments that git commit
will accept.
The second set of commands, git uuc
(Unstage and Undo Commit) and git urc
(Unstaged Restore Commit) are meant to be used as a way to make examining a commit's diff easier. When using an editor like Visual Studio Code, you can usually see your unstaged changes highlighted in some way in the editor. Using git uuc
will let you view a commit as if it was still an unstaged change, by undoing it (with git uc
) and unstaging all changes. The commit SHA is saved by this command, so to recover the commit use git urc
to put things back the way they were. Example:
$ git uuc
...view changes in visual editor...
$ git urc
Please don't use any of these without fully understanding what they're doing, as they probably have lots of corner cases that could mess up your repository.