There is a .git folder on the project. How to restore the history of commits and upload the whole history to the new repository?

$ git log Fatal: Reference has invalid format: 'refs/remotes/origin/master 
  • Does your git log output anything or what happens? - user1056837
  • The campaign does not really output - Fatal: Reference has invalid format: refs / remotes / origin / master - Vlad Shkuta
  • Vlad, try to google this error message, at least. But do not forget to backup the repository. Well, add this message to the question wording. - user1056837
  • I know how to get a similar error. But how to tell you how to fix it ... for starters, I would open the .git/refs/remotes/origin/master file and look inside. There should be one line for 40 characters plus a line break. If it is not there, then it will be necessary to "fix". - KoVadim
  • What does git reflog ? Do other people have copies of the project or on a remote repository? What did you do before the breakdown? - Nick Volynkin

1 answer 1

Look in the reflog:

 git reflog 

There will be something like this:

 4422cf4 HEAD@{1}: pull: Fast-forward 04c196f HEAD@{2}: checkout: moving from master to foo 4422cf4 HEAD@{3}: checkout: moving from feature to master 9ea2227 HEAD@{4}: reset: moving to HEAD^ b6c2674 HEAD@{5}: checkout: moving from bar to feature 

Find the appropriate commit message and reset to it:

 git reset --hard 4422cf4 

If this doesn't work, you can “fix” the .git/refs/remotes/origin/master file yourself. This file denotes a master branch. It contains a 40-character commit hash that the master branch looks at, ends with a newline.

  1. Get the full hash of the desired commit with rev-parse :

     $ git rev-parse 4422cf4 4422cf4a13713ed6c2305daeefd5105a7708fc78 
  2. Write this text to a file. You can do everything in one action:

     git rev-parse 4422cf4 > .git/refs/remotes/origin/master