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?
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.
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
Related
I am trying to update submodules in a repo. I have successfully cloned the repo and used git checkout to successfully switch to the correct branch I need to be on. When I run git submodule update --init -–recursive in that branch I get the following:
error: pathspec '–-recursive' did not match any file(s) known to git.
I have previously followed this process on a Macbook pro and did not get an error, but am currently getting the error on Windows. I have the latest version of Git installed (2.32.0). I first considered that this could be a Github SSH key issue, but I have confirmed that it asks for my SSH passphrase and proceeds with the cloning to my local machine, so probably not security related. The Git documentation states that this submodule update is mostly foolproof, so I'm unsure where to go from here. I've also tried running git submodule foreach git pull origin master before the submodule update
and same error. Any assistance is appreciated.
pathspec '–-recursive' means it interprets what should be an option as a filename/filepath instead.
Double-check your '-' (in case they are 'minus' instead of the regular 'hyphen-minus')
Make sure you are using the latest Git for Windows (2.33.0 from today)
when I am trying to commit my new local repository at GitHub from GitHub-desktop it is throwing an error "Commit failed - exit code 1 received"
Regarding:
Check first if you have added files to your index.
Open the command line and check your git status.
Second, see desktop/desktop issue 3701:
some users have run into this error due to having nested .git directories.
Can you try searching your repository to see if you have multiple .git directories?
Had a .git in my repository (which I needed) and a .git in a subfolder (which I deleted), then it worked.
Finally, check if you have any submodule (a .gitmodules file at the root of your repo).
See desktop/desktop issue 1770.
If I commit changes in submodule myself than GitHub Desktop is able to push and/or commit changes after that. After submodule is committed manually SHA1 changes from dirty. At this point I can commit to main repo.
I removed the repository from GitHub Desktop (not from the disk) and then added it again as a local repository and this solved the issue for me.
I was receiving this error as well, but unlike others I did not have have any nested .git folders. When trying to view changes, each of the files appeared as "empty" until I removed the repository from GitHub Desktop and added it again.
I encountered the same thing and it's caused by .git in subfolder.
Just removed all related .git files and the error disappeared.
exitcode 1 while committing is not always a real "error".
i do not know GitHub-desktop (and which commands exactly be executed by GitHub-desktop) but maybe your problem has the same core-"problem" as my problem some days ago.
in my case i had a branch master which tracks/follows origin/master. i executed:
git pull --no-commit --no-ff
git commit -m "merge"
i found that if origin/master has no commits which can be pulled by the git pull-command then the git commit-command is obviously doing nothing because there are no staged changes and has (imo: surprisingly) the exit-code 1 although no error occurred.
(i guess git commit should have exitcode 0 if it has really created a commit).
Resolved.
I committed via cmd prompt and did not face this issue again.
For the Github desktop,click on the plus sign on the left-hand side of your Github desktop and then select 'Discard .git' files.
I am facing issues with the git checkout command. Please help.
Here is what I did.
Created a local directory. Created some files. Initiated a git repo locally.
Created a repo in bitbucket & pushed my local repo to bitbucket
Created a new branch locally, b01
Added new files to b01, committed them and successfully pushed the branch to bitbucket
Now I am trying to merge b01 with master and that is where I am facing issues. I am not able to checkout master.
Lists of commands used and the error details:
git clone [my repo]
git checkout -b b01
Hereafter I made multiple changes, including creating new files and directories, committed those changes and successfully pushed the changes on that branch to the repo. like:
git push -u origin b01
Now I am done with the changes and want to merge it to the master branch. So I do a:
git checkout master
Here is the error it throws:
fatal: cannot create directory at 'workfolder': Permission denied
Git keeps me in b01, but deletes ALL the files I had created in the branch.
So if I now do a
git status
it shows me:
On branch b01
Your branch is upto date with 'orgin/b01'
Changes not staged for commit:
(use "git add/rm .....)
deleted: new file1
deleted: new file2
<list of the new files I had added but which got deleted as a result of the command>
I am having to run a
git checkout -- .
to restore the files.
Please help.
I had a similar situation. Though it was due to me having the solution open in visual studio. Closing visual studio and doing a git reset put me into a good spot.
I.e. check to see if any processes are locking the folder/files.
As it is already said, these could happen when another process is already accessing the files, so closing any app that could potentially be using it will help, as of me Visual Code was opened and closing it did help.
I know the question is a little bit old, but as top answer suggests using --hard flag, which may not be necessary, I decided to post this.
Probable problem cause: some other process is using/locking file/folder you're trying to remove
Solution: stop this process, then try again. One way to found it is via Resource Monitor (way I've learned from here):
Open Task Manager
Navigate to Performance tab
Click Open Resource Monitor at the bottom
Navigate to CPU tab
At Associated Handles section, there's a search field - enter path to dir/file for which you're getting 'Permission denied' error
(Review and) stop any process that appeares as search result.
Just change permission to allow one or group user for this 'workedfolder' by this
sudo chmod u+w <exact_workedfolder_permission_denied>
or
sudo chown -R user_name:user_name <exact_workedfolder_permission_denied>
First, between every operation with git I would recommend doing a quick git status. I cannot tell you how many times this has saved me lots of headaches.
A couple of things I might try to shed some light on the problem(s):
You said you created directories and made lots of changes to b01, then pushed it to the origin. Look at the commit for this action `git show . Did you change permissions on the parent directory of "workfolder"? This might be of help.
Are you on windows? If you are, how deep in directory paths are you? Is the path length exceeding windows max? Reference here.
If none of these work, have you tried creating a throwaway branch off of b01, and merging "master"? This sometimes smokes out a cause.
The ugly hail-Mary. Have you tried making a copy/paste of "b01" outside the repository, rolling back to the matching last commit of "master", and then pasting the changes in the "b01" copy over master? When things are totally upside down and not making sense, sometimes it is easier to work backwards through the problem to figure out what went wrong and learn what not to do in the future.
In my case I just checked out to the offending commit using the commit hash rather than the branch name.
304/5000
The answer to that can be quite simple. Say you want to mash your branch with a master, you can do the following:
git checkout -b master-2 // from your current branch where all the changes are
git branch -D master
git branch -m master-2 master
git push origin master
Ready! Remember that this is in case you want to overwrite everything in the branch
I have synced up with a git account via Eclipse. When I pull/fetch from head, it says that the project is fully updated.
However, when I compare some files to the version in head, it says that they no longer exist in the most recent revision. They do though.
Also, I should only have one change in my workspace, the addition of a file, but there are hundreds of files missing from head according to my Eclipse - this is not the case though.
I have tried -
Pulling/Fetching from the GIT perspective in Eclipse
Running "git reset --hard" from command line GIT (the most recent message included in the changelog was returned - but still the same issue).
There is a hidden .git at the root folder of the project, as there should be. In the Eclipse GUI, it shows the little icon for each project reflecting that it is connected to GIT.
What is my likely issue here? How can I safely troubleshoot here? I would like to avoid being castrated for removing necessary files if possible.
Edit -
There are '?' and warning symbols next to each file - but I just fetched the project from the most recent repository. Why wont these go away?
Thank you !
Using command line:
git fetch - to fetch any changes from remote repository
git checkout master (or another branch you want to see in) - to be sure you are not in detached state
git reset --hard - to discard any local changes
git clean -xdf - to clean any untracked and ignored files from tree
Now git status should show "Your branch is up-to-date"
I think you've got lost in the process of git workflow. If you are trying to work with a remote repository, you need to make sure you've set it up correctly prior to carrying out any further work.
Be careful there since git fetch and git pull serve for different purpose.
git fetch will get information from your remote repository BUT NOT merge it
git pull will get information from your remote repository AND merge it
Also, be careful when you use
git reset --hard
what it does is besically matches your working directory to last index (HEAD). If you don't have any commits to match to this will simply maintain working directory empty. If your first commit was empty and you have files in your working directory that you didn't stash or commit, it will remove the files from your working directory and revert to your previous commit.
In order to learn what's happening in your current local repository you can do a few things to better understand the content. Use following commands to learn more
On output, this will show what files changed since last commit
git status
On output, this will show which *branch you are located on
git branch
On output, this will show you your remote branches
git branch -r
On output, this will produce a narrative of all commits you've done on CURRENT branch
git log --oneline
We had a number of developers working on a large website project using Git. We have a GitHub repository and then we have the website on the server, plus all the developers have their local versions.
When we finally launched the project, I got lazy (hangs head in shame) and started making changes directly to the server, without pushing them back to the Github repo. However, other people made changes to the repo, for reasons I don't quite understand, that were never pushed down to the server and are now either outdated or wrong. We have been doing this for almost seven months.
Now the server and repo are hopelessly out of sync. I would now like to get the most updated version of the site (which is the server) back up to the Git repository so we can begin another round of development. I basically want to start with a fresh copy of what is on the server.
How would you recommend I proceed? That was the first time I had used Git. It didn't seem like such a big deal at the time but now seems like it is harder to start up again than I thought.
I have looked for instructions and don't really see anything that fits. Because I am not super confident in my Git skills, I am afraid to just start trying the few ideas I did find and losing what I have on the server.
(I know I could restore from a backup if I really messed it up but would prefer not to do that as it would take the site down.)
Can I uninstall git and start again with a fresh repo? Or is there a safe way to push the current version up to the repo?
Thanks for your help.
UPDATE: I found this answer elsewhere (Replace GitHub repo while preserving issues, wiki, etc) but I am not sure how to do this:
cd into "new" repository
git remote add origin git#github.com:myusername/myrepository (replacing myusername & myrepository accordingly)
git push --force origin master
Possibly delete other remote branches and push new ones.
Not sure what they mean by "new repository"
Make a new branch and push it to GH.
Make a new branch based on the previous
branch.
Switch to the new branch (created on #2).
Delete all the files and folders on this branch repository
except the .git folder and contains
(maintain the README.md,
.gitignore and other files if you want it).
Copy all the files from the server except
.git folder.
Commit.
Switch to local Master (created on #1)
Merge this new branch with the previous one.
Solve conflicts
(I use SmartGITthat have a visual conflict solver and helps me a lot, but you can use gitdiffif you don't want a visual interface)
Commit
Push it to GH.
I hope this helps
I figured this out. What I did was:
Make a new branch on Github to effectively store a backup.
$ git add . to stage all changes
$ git commit -m "Commit message" to commit changes
$ git push --force origin master to force changes from server to remote branch master
Once I did this, there were still hundreds of files I had deleted on the server that were not reflected on the remote github.com repository. I used the following:
$ git rm $(git ls-files --deleted)
See Removing multiple files from a Git repo that have already been deleted from disk
Then repeated git commit and git push. Now my github repo matches my server exactly.
I have not yet deleted the "backup" branch I created on github but I will.
Hope that helps someone.