2

I just created a new repository on GitHub and trying to initially push my local Java project.
I added the ssh key in my GitHub account, and it's referenced correctly by Eclipse, I assume.

I only get this error message when I'm trying to push:

Can't connect to any repository:
git@github.com:MaximStein/MyProject.git
(git@github.com:MaximStein/MyProject.git: Missing unknown
366362as232d670123a2267b4879bbd01d142426)

Any ideas?

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
Maxim
  • 227
  • 2
  • 14
  • 1
    Does that project exist under that account? You can't push there until it does. – nitind Oct 18 '21 at 22:12
  • Did you follow [these steps](https://stackoverflow.com/a/68802292/6505250)? Do you have only one GitHub project or is this for all your GitHub projects? – howlger Oct 19 '21 at 07:18
  • Which EGit/JGit version do you have? There was an issue causing _Missing unknown_, error, but that has been fixed four years ago: https://bugs.eclipse.org/bugs/show_bug.cgi?id=470318 – howlger Oct 19 '21 at 17:54
  • @Maxim Did you resolve the issue? – VonC Oct 27 '21 at 12:12
  • Typically this occurs when you edit or amend your commit before first push to a remote. If this is the case, instead of amending the first commit, simply delete the .git folder from repo folder and execute git init again. Add your remote with git remote add and make sure you create and update the .gitignore before trying to commit. I came across this multiple times when large files prevented me from trying to push my first commit, forcing me to amend my commit. – Gautam Jul 22 '23 at 13:52

2 Answers2

2

Your Git repository seems to be broken or at least in an invalid state.

The root cause seems to be Missing unknown 366362as232d670123a2267b4879bbd01d142426 which means something (probably the HEAD) points to the object with the hash 366362as232d670123a2267b4879bbd01d142426 (which will be stored in the file .git/objects/36/6362as232d670123a2267b4879bbd01d142426) that does not exist.

In the Git History you might right-click the last commit and choose Reset > Soft (HEAD Only). If commits are missing, you might be able to recover them via the Git Reflog view.

Make also sure your Eclipse and EGit/JGit is up to date (for instance, there was an issue causing a Missing unknown error that has been fixed more than four years ago) and that you do a refresh (F5) in Eclipse after you have executed Git operations on the command line.

howlger
  • 31,050
  • 11
  • 59
  • 99
0

Try first if the push would succeed from command line (which means you need in to install Git first):

  • check you are correctly identified with ssh -Tv git@github.com
  • check your remote origin URL: git remote -v
  • check your local status (git status: to make sure you are on a branch, here I assume main, and that you have made at least one commit)
  • check your initial push: git push -u origin main

Check also if you have declared any submodules (.gitmodules file), or look for any nested Git repository (.git subfolder anywhere beside your repository root folder)

It is helpful to rule out (or not) a git-core issue, before investigation an Egit/JGit one.

And the OP Maxim confirms in the comments:

It's a good idea to try it in the command line first.

It says "fatal: bad object HEAD" when I do git status.
I think I've only made one local commit for that project.

Indeed, making local commits, in a branch, is a prerequisite to pushing anything.
In your case, do a git branch -avv to check if there are any.

If you already pushed that missing commit, assuming your main branch is main (not master):

git fetch origin
git reset --soft origin/main
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • You answer does not work for me: `'git' is not recognized as an internal or external command, operable program or batch file.`. – howlger Oct 19 '21 at 06:53
  • @howlger Yes, it does suppose you have Git installed (since Eclipse, through Egit, is using JGit, and does not rely on Git directly) – VonC Oct 19 '21 at 06:55
  • Your answer does not make sense for EGit/JGit. `ssh -Tv git@github.com` might fail while it works with EGit and vice versa, etc. It is not helpful to answer EGit questions as if they would be git-core questions. – howlger Oct 19 '21 at 07:07
  • @howlger First, check if the issue persists from command line. Then go back to the IDE. That is how I would troubleshoot this issue. – VonC Oct 19 '21 at 07:07
  • If it works on the command line doesn't mean it will work in EGit and vice versa. – howlger Oct 19 '21 at 07:14
  • It's a good idea to try it in the command line first. It says "fatal: bad object HEAD" when I do git status. I think I've only made one local commit for that project. – Maxim Oct 19 '21 at 07:21
  • @Maxim Thank you for the feedback. I have included your comment in the answer for more visibility. – VonC Oct 19 '21 at 12:29
  • @VonC The addition looks passive-aggressive to me. – howlger Oct 19 '21 at 17:26
  • @howlger I am sincerely sorry, that was not the intention. Feel free to edit the answer and include your opinion much better than I could. – VonC Oct 19 '21 at 18:00
  • @VonC Please remove it. I don't understand what you mean by _"Indeed, making local commits, in a branch, is a prerequisite to pushing anything."_ It was said that one local commit was made. How to push nothing in EGit? – howlger Oct 19 '21 at 18:51