0

I mistankely force pushed an outdated version of master branch I had on local to remote and reverted a bunch of commits.

To try to fix this, I cherry-picked all of the commits merged after the commit I reverted to and merged them into the master branch through a new pull request.

Will doing this fix my mistake? The code is now the same as before but the commits have different sha's.

CarlosC
  • 1
  • 1
  • Do you know the commit hash before pushing? Do you have it fetched/cloned somewhere? Do you have access to the repo on the server? – knittl Jan 05 '23 at 19:50
  • I do have the commit hash before pushing. I've tried to checkout to that commit locally and it says the commit does not exist. I had access to the repo on github from where I went through every pull request approved & merged after the the push commit to rebuild. I'm not sure if that's enougth thought. One of my colleagues might have the latest master but I'm not sure. – CarlosC Jan 05 '23 at 19:53
  • You can try to fetch this commit hash: https://stackoverflow.com/questions/14872486/retrieve-specific-commit-from-a-remote-git-repository – I think this will work for GitHub repos. – knittl Jan 05 '23 at 20:00

1 Answers1

0

and reverted a bunch of commits.

You didn't revert the commits, you pointed master to a different spot. The difference is subtle but important to understand.

Cherry-picking the commits back onto the branch is one way to go back to the desired code and it will produce the correct result if you don't miss any commits. The history may be different (different SHAs) but the code will be the same (which is what really matters in most cases).

(Different SHAs may be a problem [a nuisance] if you work with other people because the history has changed).

tymtam
  • 31,798
  • 8
  • 86
  • 126