Same as last one but for two commits back:

git reset --hard HEAD^^

Don’t reset after pushing

Reset Workflow
  • Edit file again ‘edit_this_file.rb’
  • Check status
  • Add and commit with wrong message
  • Check log
  • Amend commit
  • Check log
  • Soft reset
  • Check log
  • Pull for updates
  • Push changes
  • Commands

    # Change file edit_this_file.rb
    git status
    git commit -am "kjkfjkg"
    git log
    git commit --amend -m "New comment added"
    git log
    git reset --soft HEAD^
    git log
    git pull origin master
    git push origin master
    git revert vs git reset
    
  • Reset removes the commit while revert removes the changes but leaves the commit
  • Revert is safer considering we can revert a revert
  • # Changed file
    git commit -am "bug introduced"
    git revert HEAD
    # New commit created reverting changes
    # Now we want to re apply the reverted commit
    git log # take hash from the revert commit
    git revert <rev commit hash>
    # reverted commit is back (new commit created again)
    

    Docs

    Edit this page to fix an error or add an improvement in a merge request.
    Create an issue to suggest an improvement to this page.

    Product

    Create an issue if there's something you don't like about this feature.
    Propose functionality by submitting a feature request.
    Join First Look to help shape new features.

    Feature availability and product trials

    View pricing to see all GitLab tiers and features, or to upgrade.
    Try GitLab for free with access to all features for 30 days.

    Get Help

    If you didn't find what you were looking for, search the docs.
    If you want help with something specific and could use community support, post on the GitLab forum.
    For problems setting up or using this feature (depending on your GitLab subscription).

    Request support