how to cancel a commit in Git
I want to cancel the blue commit
Is there a effective way to do it???
- How can I recover from an erronous git push -f origin master?
- Is it possible to set a git commit to have a timestamp prior to 1970?
- Reset all changes after last commit in git
- GIT on push to a remote server exlude folders/files
- How to checkout a commit's child?
- Remove sensitive files and their commits from Git history
3 Solutions collect form web for “how to cancel a commit in Git”
I think that you have a couple options for getting rid of that commit (and some are mentioned in the comments above):
git revert <commit_id>– this will show in the git history that you specifically removed the code
git reset --hard <commit_id_before_your_commit>then cherry pick the commits you want to keep
git cherry-pick <commit_id_to_keep>x2 and finally force push to the origin
git rebase -i origin/wix– interactive rebase the branch, and SKIP that commit when you get to it
The latter two options will not show any trace of that commit in your branch history, where as the first option will show that the commit existed but you opted to remove it.
You can do a revert
git revert <commit-id>
Additionally to the revert:
If you haven’t pushed the changes yet (the line saying
remotes/origin/wlx suggesting that):
> git rebase -i remotes/origin/wlx
This will open an editor asking you what to do with the commits. Deleting any of the lines will drop that commit from the history.