Receiving "fatal: Not a git repository" when attempting to remote add a Git repo

  • 5,000
  • Tác giả: admin
  • Ngày đăng:
  • Lượt xem: 5
  • Tình trạng: Còn hàng

NOTE: this does not answer to lớn the common problem, which was OP’s problem, but to lớn different problem where this error message may come up. I didn’t feel lượt thích doing new question just to lớn write this answer down, tell u if I should bởi that instead :P

I got to lớn situation, most likely due to lớn some corruption of certain crash I had, that I got this error even when .git did exist.

smar@aaeru ~/P/Nominatim> git status
fatal: Not a git repository (or any of the parent directories): .git
smar@aaeru ~/P/Nominatim [128]> ls .git
COMMIT_EDITMSG  config*  FETCH_HEAD  HEAD  index  logs/  modules/  objects/  ORIG_HEAD packed-refs

Since I didn’t have anything that really needed preserving, I just went with dummy way, and did...

smar@aaeru ~/P/Nominatim [128]> git init
Reinitialized existing Git repository in /home/smar/Projektit/Nominatim/.git/

Still not working though, as for example git log returns fatal: bad mặc định revision 'HEAD'. Remotes were there though, so sánh I did git fetch --all and then just git reset --hard origin/master to lớn get myself to lớn the state the repo was previously.

Note that if there is some uncommitted changes, you can see them with git status, git diff and so sánh on. Then just git diff yourfile > patch before running the reset.

At least for u reflog (git reflog) disappeared completely. Hence, if you bởi the reset, and there was some changes you wanted to lớn prevent, I’m not sure you can get them back after reset anymore. So, make sure that you have all changes you can’t lose backed up, ultimately by just copying the clone before trying this.