git-plus
git-plus copied to clipboard
Undo Last Commit
My workflow often involves committing changes to feature or bugfix branches, and it's easy to accidentally commit to the wrong branch.
It'd be nice if there was an easy command to perform the task of undoing a recent commit and unstaging those changes, all in one go.
Undo Last Commit: git reset HEAD~1
Edit: git reset HEAD@{1}
is safer as it can be called multiple times and merely undoes and redoes itself.
The best implementation would actively check for a previous commit before naively running, but hey.
+1
For now you can use the Run
command to do this.
I've just published a new version with a feature that allows users to define their own commonly used commands locally. It's an experimental feature right now and I would love if you gave it a try and provided feedback.
You can read about it here
I will be trying it, thanks a lot!
That works fantastically! Thanks again.
I updated the undo command to be safe to call multiple times (now it undoes and redoes itself infinitely):
atom.packages.onDidActivateInitialPackages (p) ->
if gitPlus = atom.packages.getActivePackage('git-plus')?.mainModule.provideService()
# Undo Last Commit
# This reset targets the previous line in the git reflog, so it can be called again to undo itself.
gitPlus.registerCommand 'atom-text-editor', 'akonwi:undo-last-commit', ->
gitPlus.getRepo() # If there are multiple repos in the project, you will be prompted to select which to use
.then (repo) -> gitPlus.run repo, 'reset HEAD@{1}'
Curious, why do commands require the akonwi:
prefix (your user name) when being registered?
The prefix can be whatever you want. It's just an identifier to keep commands unique from another package that might use the same name.
Sweet, thanks again.