0
$ git init
Initialized empty Git repository in C:/Users/myname/IdeaProjects/ProjectName/.git
$ git remote add origin https://myname@bitbucket.org/abc/xyz-repository.git
$ git status
On branch master
No commits yet
Untracked files:
(use "git add <file>..." to include in what will be committed)
.gitignore
.idea/
ProjectName.iml
generated-sources/
pom.xml
src/
nothing added to commit but untracked files present (use "git add" to track)
$ git add . 

FEW WARNINGS...

$git commit -am "New Project"

$ git push -f origin master 

Now every folder and file in the xyz-repository.git is replaced with the new files making a new master branch overriding the existing once, ALL commit ids are gone.

How can I revert all I have done? I want to go back to the previous master branch which has folders and files.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143
Mr.MV
  • 1
  • 3
  • 1
    This is why you should never force-push to `master`, or let people do so... – underscore_d Jun 16 '20 at 15:00
  • 1
    seems like a dupe of [How to recover from a git push -force?](https://stackoverflow.com/questions/12568628/how-to-recover-from-a-git-push-force) – underscore_d Jun 16 '20 at 15:00
  • @underscore_d how is this different from **How to recover from a git push -force?** All the existing commits were lost and replaced with the new commit id. – Mr.MV Jun 16 '20 at 15:24
  • 1
    That's still a force push. It doesn't matter how much of the history was rewritten: it _was_. Recovery follows the same principles either way. – underscore_d Jun 16 '20 at 15:25
  • @underscore_d really thank you:) it worked now after a little bit of depth understanding. Thank you very much. – Mr.MV Jun 16 '20 at 17:54
  • Glad to hear it! :-D – underscore_d Jun 16 '20 at 19:08

0 Answers0