1

I was on a branch where my colleague pushed a couple of commits since my last pull.

Now, git told me to pull first.
I however insisted to push my changes, so I added a --force flag.

Now this branch has my commit as HEAD with no way for me to pull the commits from my colleague, or restore the state before my push.

Is there any way to undo this?

LinFelix
  • 1,026
  • 1
  • 13
  • 23
donjonson
  • 53
  • 3
  • 3
    If your colleague still has his commit, the simplest way is for him to force push – LeGEC Nov 11 '21 at 12:28
  • 2
    BTW, this sort of thing is IMHO a good reason to get in the habit of using `--force-with-lease` instead of `--force`, even when you're absolutely sure that nobody else changed anything on the remote. – Hasturkun Nov 11 '21 at 14:37
  • @Hasturkun Good point. I have detailed that in "[`git push --force-with-lease` vs. `--force`](https://stackoverflow.com/a/52937476/6309)". – VonC Nov 12 '21 at 09:52

1 Answers1

2

If your colleague is not available to force push their own branch, you can check with the Git hosting server you are pushing to.

  • an on-premise server might have an admin able to get the reflog of the target remote repository, getting back the past reference of the branch overridden.
  • a GitHub repository would allow you to query push events, getting the past reference that way

The OP donjonson confirms the simplest option in the comments:

At the end of the day, my colleague answered my calls and that solved the problem.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Hey, yeah at the end of the day my colleague answered my calls and that solved the problem, thanks a lot:) – donjonson Nov 12 '21 at 12:25
  • @donjonson Thank you for the feedback. I have included your comment in the answer for more visibility. – VonC Nov 12 '21 at 13:28