1

I wanted to revert a pushed commit and because of lack of knowledge I did

git reset --hard HEAD~1 
git push -f 

Now , after this , people who already had pulled the commit which i reset , they are not able to go back . git pull does not take them 1 commit back .

How do I solve this mess now ? Any suggestions.

Romain Valeri
  • 19,645
  • 3
  • 36
  • 61
CodeTry
  • 312
  • 1
  • 19
  • https://stackoverflow.com/questions/1125968/how-do-i-force-git-pull-to-overwrite-local-files – Alexan Mar 25 '19 at 19:05
  • they should do hard reset too: `git reset --hard HEAD`, then pull, but they will lost their local changes – Alexan Mar 25 '19 at 19:07
  • Can `git stash` backup their work before they reset? – simbo1905 Mar 25 '19 at 19:27
  • @simbo1905 Yes, and it's even maybe a better solution than committing on the branch, since it might soon be reset. And I'd even advocate for a branch backup before the reset, just in case... – Romain Valeri Mar 25 '19 at 19:32
  • You can also go back to their version and use `git revert` – Jona Mar 25 '19 at 19:37

1 Answers1

2

Disclaimer : In all cases, before doing anything, be sure to :

  • discuss it in details with your team so that you all agree on a plan

  • everyone saves/commits their local changes before reseting anything, either with git stash like hinted at by simbo1905 in his comment, or by commiting on the branch then backing it up with

    git branch backup-branch old-branch


Now in short, 2 approaches, depending on the specifics of your project and the nature of the changes you just pushed :

1) either everyone goes for your version

Every other user updates his/her local branch with

git fetch
git reset --hard <remoteName>/<branchName>

2) or their version is to be kept

In this case, one of the other users with the old ref for this branch* does a git push -f <remoteName> <branchName>, and you are to do the above operations to sync back with them.

* (in case noone can do that for any reason, you could also recover the ref locally from the branch's reflog and push it again to remote with force, it's just often quicker to push it from the repo of someone with the old ref)

Community
  • 1
  • 1
Romain Valeri
  • 19,645
  • 3
  • 36
  • 61