0

What I am trying to do : Rolling back branch1 to some previous commit and then rebasing it on top of master branch.

There are two branches say branch1 and master. I rolled back branch1 to some previous commit using reset --hard.

After that I rebased branch1 on top of master. After resolving the conflicts, when I try to push, it gives non-fast forward error.

I tried git push -f -u origin branch1, git push +branch1 but none of them worked. How to successfully push in this case ?

  • 2
    What exactly did "not work" with `git push -f -u origin branch1`? – mkrieger1 Apr 15 '22 at 16:39
  • @mkrieger1 To prevent you from losing history, non-fast-forward updates were rejected Merge the remote changes before pushing again. And push was failed – TheReal__Mike Apr 15 '22 at 16:49
  • So that's the explanation. You need to either edit the configuration of the repository on the server to allow non-fast-forward updates, or merge the remote changes before pushing again. – mkrieger1 Apr 15 '22 at 16:52
  • @mkrieger1 by merging the remote changes it means I can't really bring it back to previous commit (since the new changes in remote will again get merged)? – TheReal__Mike Apr 15 '22 at 16:54
  • Yes you can. See https://stackoverflow.com/questions/4114095/how-do-i-revert-a-git-repository-to-a-previous-commit, section "Undo published commits with new commits". You could also just push your rebased commits as a new branch that is different from `branch1`. – mkrieger1 Apr 15 '22 at 16:56
  • 1
    A hosting system (e.g., GitHub) can refuse a `git push` even with the `--force` flag. Git doesn't do that on its own though. So if it didn't work, you need to say *why* it didn't work: perhaps it was because GitHub (not Git) used a GitHub (not Git) rule to reject the push, in which case you have to do something on GitHub (not Git) to fix this. – torek Apr 16 '22 at 04:34

0 Answers0