0

Before I do this just want some clarification:

git push -f origin develop

This will overwrite the branch on my remote repo called develop.

Will I be able to revert back to the previous commit on remote repo after doing this?

amegyoushi
  • 524
  • 4
  • 14
user892134
  • 3,078
  • 16
  • 62
  • 128
  • Possible duplicate of [How to recover from a git push -force?](https://stackoverflow.com/questions/12568628/how-to-recover-from-a-git-push-force) – phd Nov 05 '18 at 11:39
  • https://stackoverflow.com/search?q=%5Bgit%5D+undo+force+push – phd Nov 05 '18 at 11:39

1 Answers1

3

Possibly not. You may lose some of your history.

If you have rewritten the history of your local repo such that the previous commit is gone, then once you force push those changes to the server you will not be able to get it back. Performing a force push makes the server copy match your local copy exactly, including any modifications to history.

If your goal isn't to rewrite history, I would recommend the following steps:

  1. Do a git pull to merge your remote repository with the remote repository. You will probably have merge conflicts.

  2. Resolve the merge conflicts by hand.

  3. Commit your resolution of the merge conflicts.

  4. Do a normal push once the merge conflicts are resolved.

Seth
  • 338
  • 1
  • 9
  • ok, how do i push to remote repo branch but ignore merge conflicts.So the local code overwrites remote code and i still can revert? I thought it was force push. – user892134 Nov 04 '18 at 03:42
  • @user892134 Without more information as to how you got to your current state, it's tough for me to help you. What is your end goal, and what have you tried so far to get to your current status? I've updated my answer with some recommendations. – Seth Nov 04 '18 at 03:45
  • @user892134 force pushing will overwrite the remote code, but you (probably) won't be able to revert to the state that you've force pushed over. You can revert if the revert can occur w.r.t. your local branch. – Matt Messersmith Nov 04 '18 at 14:17