0

I used "git push origin -f --mirror" to push the renaming change I made to one of the branches. Then it somehow deleted several other branches in the repo. How can I roll back one push and make all the deleted branch come back?

Angelo
  • 185
  • 1
  • 2
  • 15

1 Answers1

0

There isn't a single command that will let you undo a push. However, there's still hope.

If the branch which have been deleted in origin is still present in your local repo, you just need to push it back:

git push origin <my_deleted_branch>

If you don't have this branch in your local repo anymore, then your question becomes "how can I recover a deleted branch". Fortunately this question has already been answered a lot of time. For instance here: https://stackoverflow.com/a/1992485/1796345


Update: If your repo isn't up to date, ie: if there are commits that were only in the remote repo and not in the local one, then it's obviously hopeless to look only in this local repo.

Ideally you should try to recover the lost branch from the remote repo. But since it seems your origin is on github, then I guess your best move would to check if your colleagues have those missing commits.

Community
  • 1
  • 1
gturri
  • 13,807
  • 9
  • 40
  • 57
  • I am not 100% if my local repo is the most up-to-date version of the remote. Does it matter that my local repo is a few days later than the remote? – Angelo Mar 13 '17 at 14:21
  • I tried "git checkout origin/BranchName" to retrieve a deleted remote branch. It reports the pathsec ... did not match any file(s) known to git. – Angelo Mar 13 '17 at 14:29
  • The "git flog" command only shows a singular log. But different people made different changes on the different remote branch. – Angelo Mar 13 '17 at 14:39