how to cancel a commit in Git

enter image description here

I want to cancel the blue commit
Is there a effective way to do it???
Thanks!

  • Tried to remove files from git, now branches are diverged and I can't push the changes
  • Get Multiple line commit message in jenkins email notification
  • How to checkout a commit's child?
  • How to amend several commits in Git to change author
  • Git missing commits
  • How can I change text for a commit that I did some times ago in git
  • Why does jenkins build from multiple commits when it shouldn't?
  • Calculate time between git commits
  • 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):

    1. git revert <commit_id> – this will show in the git history that you specifically removed the code
    2. 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
    3. 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.

    Git Baby is a git and github fan, let's start git clone.