It’s as simple as this:
git reset HEAD^
Note: some shells treat ^
as a special character (for example some Windows shells or ZSH with globbing enabled), so you may have to quote "HEAD^"
or use HEAD~1
in those cases.
git reset
without a --hard
or --soft
moves your HEAD
to point to the specified commit, without changing any files. HEAD^
refers to the (first) parent commit of your current commit, which in your case is the commit before the temporary one.
Note that another option is to carry on as normal, and then at the next commit point instead run:
git commit --amend [-m … etc]
which will instead edit the most recent commit, having the same effect as above.
Note that this (as with nearly every git answer) can cause problems if you’ve already pushed the bad commit to a place where someone else may have pulled it from. Try to avoid that
Related Posts:
- How to uncommit my last commit in Git [duplicate]
- How to uncommit my last commit in Git [duplicate]
- What is difference between ‘git reset –hard HEAD~1’ and ‘git reset –soft HEAD~1’?
- git undo all uncommitted or unsaved changes
- How do I use ‘git reset –hard HEAD’ to revert to a previous commit? [duplicate]
- How do I undo the most recent local commits in Git?
- How do I revert a Git repository to a previous commit?
- Undo a Git merge that hasn’t been pushed yet
- What is the `git restore` command and what is the difference between `git restore` and `git reset`?
- Reset local repository branch to be just like remote repository HEAD
- Delete commits from a branch in Git
- Why are there two ways to unstage a file in Git?
- Undoing a git rebase
- Undoing a git rebase
- How do I revert a Git repository to a previous commit?
- Reset local repository branch to be just like remote repository HEAD
- What is the meaning of git reset –hard origin/master?
- How to undo git reset –soft to get my changes back?
- How can I undo git reset –hard HEAD~1?
- Move existing, uncommitted work to a new branch in Git
- How do I “un-revert” a reverted Git commit?
- How do I check out a remote Git branch?
- How do I delete a Git branch locally and remotely?
- What is git tag, How to create tags & How to checkout git remote tag(s)
- How do I delete a Git branch locally and remotely?
- How do I rename a local Git branch?
- What does ‘–set-upstream’ do?
- What does ‘–set-upstream’ do?
- Difference between “git add -A” and “git add .”
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- error: src refspec master does not match any
- What does cherry-picking a commit with Git mean?
- How to cherry pick from 1 branch to another
- How to Git stash pop specific stash in 1.8.3?
- How to use Git Revert
- What is the best (and safest) way to merge a Git branch into master?
- How to merge branch to master?
- Git: How do I force “git pull” to overwrite local files?
- Differences between git pull origin master & git pull origin/master
- How do I force git pull to overwrite everything on every pull?
- What happens when I do git pull origin master in the develop branch?
- How do I properly force a Git push?
- How do I rename a local Git branch?
- fatal: Not a git repository (or any of the parent directories): .git [duplicate]
- Why is “MINGW64” appearing on my Git bash?
- How can I switch to another branch in git?
- How to remove local (untracked) files from the current Git working tree
- Squash my last X commits together using Git
- Git merge hotfix branch into feature branch
- Git refusing to merge unrelated histories on rebase
- Git submodule update
- How to apply a patch generated with git format-patch?
- How do I discard unstaged changes in Git?
- What does ‘git merge –abort is equivalent to git reset –merge when MERGE_HEAD is present.’ of Git merge man page mean?
- What does ‘git blame’ do?
- Abort a Git Merge
- What is the difference between git push origin and git push origin master
- GitHub: Permission denied (publickey). fatal: Could not read from remote repository
- Git fetch remote branch
- How to delete a remote tag?
- Updates were rejected because the tip of your current branch is behind its remote counterpart
- Updates were rejected because the tip of your current branch is behind its remote counterpart
- Git: How do I force “git pull” to overwrite local files?
- git error: failed to push some refs to remote
- git stash apply version
- How to modify existing, unpushed commit messages?
- How do I clone a specific Git branch? [duplicate]
- Git pushing to remote branch
- How to revert a merge commit that’s already pushed to remote branch?
- What is Git pruning?
- Git pushing to remote branch
- git – remote add origin vs remote set-url origin
- How do I undo ‘git add’ before commit?
- How do I discard unstaged changes in Git?
- Git: Message ‘src refspec master does not match any’ when pushing commits in Git
- GitHub Error Message – Permission denied (publickey)
- Git fetch remote branch
- How can I see the differences between two branches?
- How to upgrade Git on Windows to the latest version
- How do I push a new local branch to a remote Git repository and track it too?
- Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- Handling file renames in Git
- How do I list all remote branches in Git 1.7+?
- Practical uses of git reset –soft?
- Need to reset git branch to origin version
- How do I push a new local branch to a remote Git repository and track it too?
- Git is not working after macOS Update (xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools)
- Updating a local repository with changes from a GitHub repository
- ‘git’ is not recognized as an internal or external command
- Git: How to solve Permission denied (publickey) error when using Git?
- How do I remove a submodule?
- LF will be replaced by CRLF in git – What is that and is it important? [duplicate]
- git: fatal: Could not read from remote repository
- Git push results in “Authentication Failed”
- What does “Changes not staged for commit” mean
- Git error: “Please make sure you have the correct access rights and the repository exists”
- github changes not staged for commit
- Git : fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists
- Windows git “warning: LF will be replaced by CRLF”, is that warning tail backward?