0

I have two branches on git - master and main. I wanted to push all my work from the main to the master branch. What I did instead was pushing all my work from the master branch to the main branch. Now all my work from the main branch is gone. I cannot just access a past commit from main because all the commits got replaced from the commits of the master branch.

How can I revert this step to get my old main branch back?

Git commands I used for the mistake

git checkout master   
git branch main master -f    
git checkout main  
git push origin main -f 

What I wanted to do instead (I guess)

git checkout main   
git branch master main -f    
git checkout master  
git push origin master -f 
teres
  • 53
  • 6
  • `git branch main main -f` Are you moving the head of `main` to the head of `main`? That's meaningless. Please fix so we can understand what you really want. Also you use too many checkouts; you really don't need so many; most commands you've shown don't operate on the current branch; but that's just a minor nitpick, not a real problem. – phd Aug 03 '22 at 07:43
  • 1
    Thanks. I fixed it - I was planning to move the head from main to master. Is it now understandable or still unclear? What is wrong with the checkouts? @phd – teres Aug 03 '22 at 09:08

1 Answers1

0

I used git reflog show --all for displaying the reference history. With git reset --hard someHashLike3945493 I got the commit back. Like its stated here.

teres
  • 53
  • 6