Search code examples
gittortoisegitgit-reset

Tortoise GIT Rollback to previous commit


I'm using Tortoise GIT and would like to discard recent commits and reverting to a specific commit.

My attempt to do this is as follows.

  • View Log.
  • Select commit to revert to.
  • Select reset.
  • Push

When I attempt to push I get an error

[rejected]          my branch -> mybranch (non-fast-forward)
hint: Updates were rejected because the tip of your current branch is
behind hint: its remote counterpart. Integrate the remote changes
(e.g. hint: 'git pull ...') before pushing again.

What am I doing wrong?

For info, I tried selecting the commits and selecting revert, however this failed on two commits which were merges from another branch. I'd therefore like to skip the revert and reset to the version before these commits.

I don't have permissions to force the push.

If I perform a pull, this simply reverts back to the original head.

Thanks for any help.


Solution

  • If you're doing a git reset and you pushed those commits already, you need a force push as you're rewriting history. (side node, to do a force push in TortoiseGit, select the "known changes" checkbox)

    But another option is to revert the commits, which create a new commit with the reverted changes.

    You could do that as follows in TortoiseGit:

    1. Go to the commit log

    2. Select the commit(s) to revert and select 'Revert changes by these commit(s)'

      enter image description here

    3. Those reverts are now in your local branch. So go to the commit dialog to create a new commit.

    4. And just push