2

I am trying to rewind my repository a few commits back.

After opening the commit log, I choose the commit that I want to rewind to, then Reset "master" to this..., then Hard: Reset working tree and index.

When opening the logs again, all later commits are indeed gone.

But when I pull the repository from clean, they're back in there.

This task used to be simple with Subversion (although, not entirely deleting a bunch of commits, just reverting to a previous commit, which doesn't show in Tortoise Git menu unless you choose THE previous commit, i.e., one before most recent).

Any idea how to achieve my goal?

halfer
  • 19,824
  • 17
  • 99
  • 186
goodvibration
  • 5,980
  • 4
  • 28
  • 61
  • 1
    ...all later commits are indeed gone. Then you should do a `git push -f` to **rewrite** the remote, or we say, "sync" this edit. – Geno Chen Dec 26 '18 at 09:17
  • @GenoChen: Thank you, but I tried that; Got an error message saying I need to pull first because I'm not pointing to latest. Then, after pulling, everything is back to where it was. – goodvibration Dec 26 '18 at 09:18
  • Did you add the `-f` or `--force` parameter? – Geno Chen Dec 26 '18 at 09:20
  • @GenoChen: Doing it via Tortoise, so don't recall seeing such option, but will try again; one sec please... – goodvibration Dec 26 '18 at 09:22
  • Then I wonder if there is a checkbox saying something like "Force push" when you are preparing for a push... – Geno Chen Dec 26 '18 at 09:24
  • @GenoChen: Yes!!! Well, similar. There's a title `Force` with two check-boxes - `known changes` and `unknown changes`. When I marked the first, the second was disabled. And `push` completed successfully this time! After pulling from clean, all later commits are gone. Thank you!!! – goodvibration Dec 26 '18 at 09:26
  • If you want to revert via command line, see https://stackoverflow.com/questions/1463340/how-to-revert-multiple-git-commits – Michael Freidgeim Feb 24 '20 at 21:23

2 Answers2

5

The menu Reset "master" just means "Reset local master", not a remote master.

That is, no remote operation is occured when you click this option. This is a basic difference between Git and SVN: Git does many local operations, just do remote operation when needed, but all operation in SVN are remote required.

To update, or we say sync the modification of your resetting, just do a git push -f to force rewrite the remote.

Warning: Check twice, make sure you are clear what you are doing before executing git push -f, or you may lost your necessary work.

Geno Chen
  • 4,916
  • 6
  • 21
  • 39
0

To force remote update is a risky operation and may be even not allowed.
E.g. I’ve received on GitHub

remote: error: GH006: Protected branch update failed for refs/heads/master.
remote: error: Cannot force-push to this protected branch

The better suggestion from  https://github.com/hexojs/hexo/issues/2817#issuecomment-432715832 :

 1. Create a new branch,
2. commit your code to the branch
3. and do a pull request.
4. Someone will have to approve it depending on repo settings.

Michael Freidgeim
  • 26,542
  • 16
  • 152
  • 170