0

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.

user5265160
  • 409
  • 1
  • 8
  • 19
  • 1
    Try pulling with `git pull origin ` and then do a force push with `git push -f origin ` . Hoping no one else is using your branch ,you can force push. – Dev-vruper Feb 25 '21 at 13:59
  • Thanks. I'm afraid I don't have permissions to force the push. – user5265160 Feb 25 '21 at 14:02
  • 1
    If that's the case , i think `git revert` can be of more help here . You can try to revert those 2 merge commits using `git revert -m 1` . Take a look at this,if it helps at all : https://stackoverflow.com/q/10544139/6309111 – Dev-vruper Feb 25 '21 at 14:11
  • Thanks. Does tortoise provide a command line? I was hoping trying to use the UI. – user5265160 Feb 25 '21 at 15:23

1 Answers1

3

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

Julian
  • 33,915
  • 22
  • 119
  • 174
  • Thanks. I tried individually reverting the changes, however this failed because some of the changes contained big merges and this produced complicated errors. So I thought it would be better to reset to the version before these changes. Yes, it makes sense that the force option is required to push commits on top of a reset. – user5265160 Mar 01 '21 at 11:22
  • Yes it's hard with merges. My advise is to prevent merges by doing squashed pull request merges (e.g. when using GitHub) and doing pulled rebases. – Julian Mar 01 '21 at 11:34