Question on moving computers

Hello all.

So currently, I am having my computer where I do all my github work repaired because it has broken once again (thanks apple). Anyways, I have a temporary computer that I am using, that has a backup of my work from the computer that is currently being fixed. The problem is, because this is a new machine, git and command line recognizes my files as foreign, and does not allow me to make new commits. Suggestions?

How did you back it up/restored it? Did you also copy the hidden .git subdirectory?

If you copied EVERYTHING, including the hidden .git directory, and the hidden .gitignore file, the new project directory in your new computer should work the same as the old computer.

If you didn’t copy the .git directory, then you’ll get a
"fatal: Not a git repository (or any of the parent directories): .git"
if you try to do any git command

If you don’t care what’s in the git history from the old project directory, I guess you can just do another git init on your new project directory and start again from there.

I do have the .git folder and the .gitignore in my new project on the computer, however I get the terminal error

error: invalid object 100644 2cf4dcd1a43d04be9583a86e5d4179306f5299ab for '.gitignore'
error: invalid object 100644 2cf4dcd1a43d04be9583a86e5d4179306f5299ab for '.gitignore'
error: Error building trees

every time I try and make a commit

It seems the hash object for the file .gitignore is missing.

You can try regenerating it. Try this
git hash-object -w .gitignore

I did that, now there’s a problem with readme…

error: invalid object 100644 f20eea6021fd71f85915a271fdd0d1a3751bcc65 for 'README.md'
error: invalid object 100644 f20eea6021fd71f85915a271fdd0d1a3751bcc65 for 'README.md'
error: Error building trees

EDIT:

I did the hash object command with every file:

this is the current error I am getting in console

fatal: could not parse HEAD

Sounds like the .git directory you copied got corrupted in the copy process?

How did you backed it up in the first place? Just a straight copy?

I’m backed up on an external harddrive but the file I have for the .git folder is from icloud, can I just clone it again off my repo to fix it?

WAIT… so when you backup your project files you DID NOT really copy the .git folder…
Instead you used the .git folder from a different repo/time of the same project?

@owel

Apple has an automated iCloud sync service that allows the user to pull their documents off the cloud from a new computer. That is what I did, however it should have been a carbon copy from my other computer. Should I just download the .git folder again from my git repo that is online?

you should have copied the .git folder to the external hard drive, at the same time you copied your project directory.

You may be SOL. And to recover, you may have no choice but to delete .git and do a new init. – but that would lose all your past history. But that would make git working again.

@owel I just cloned it again from the repo and can commit again. No harm done.

1 Like