1

This is my first question, and I tried to search the forum and google for answers but am hitting a block.

So I'm saving my git files on Google Drive. After creating 5 commits, I get the output as below from the git log --oneline

5c1bd8f (HEAD -> master) 5th commit - robots.txt
ca656ac 4th commit - robots.txt
3850e6c 3rd commit - robots.txt
bd5b39f 2nd commit - robots.txt
6f3ee36 1st commit - robots.txt
a177016 All files committed

I then proceed to create a new branch by switching to the 2nd commit by typing git checkout bd5b39f.

However, when I want to go back to master, by typing git checkout master, I get the below output.

$ git checkout master
fatal: bad object refs/desktop.ini

I have googled it up and found this solution: Git / Google Drive Bad References

Cleanup was fairly simple once I realised what was going on:

  1. Pause Google Drive to prevent further interference.
  2. Delete all the hidden desktop.ini files in the repository. I did this via a command-line window, but it should be possible via Windows Explorer with the right options.
  3. Compress the Git database.
  4. Resume Google Drive.

I have tried to delete the desktop.ini file using Windows Explorer and also the command line, only to come up with this output.

$ git checkout master
fatal: bad object refs/desktop.ini
D       desktop.ini

I did not understand Step 3 - Compress the Git Database.

I also checked out this link from stackoverflow which was similar but not the same: Fatal Bad Objects

$ git gc
error: bad ref for .git/logs/refs/heads/desktop.ini
error: bad ref for .git/logs/refs/desktop.ini
fatal: bad object refs/desktop.ini
fatal: failed to run repack

Would appreciate any help provided.

ripalo
  • 98
  • 6

3 Answers3

0

Ok. I think I know how to solve this, but I don't know the theory behind so if anyone could highlight the theory it would be much appreciated.

Apparently the commit which i branched out from when I input:

git checkout <commithash>

was not a branch.

After having a detached HEAD , I tried to to input a new branch:

git checkout -b newbranch

and from there, i could checkout to master.

The log output after committing

$ git log --oneline
44f1480 (HEAD) 6th commit
cf8add8 test2
72e8617 test1
c12d36f robots.txt - 2nd A commit
57d8a08 robots.txt - 2nd commit
ed9b73f robots.txt - 1st commit
08ab2a3 All files Committed

The log output after git checkout -b newbranch

$ git log --oneline
44f1480 (HEAD -> newbranch) 6th commit
cf8add8 test2
72e8617 test1
c12d36f robots.txt - 2nd A commit
57d8a08 robots.txt - 2nd commit
ed9b73f robots.txt - 1st commit
08ab2a3 All files Committed

Notice 44f1480 (HEAD -> newbranch). Not sure if this is the correct way to solve it but it worked for me.

ripalo
  • 98
  • 6
0

I just recently ran into this problem when trying to view the Git Graph extension in VS Code. I found it was nothing to do with having a wrong checkout so thought I'd add my solution on here for others.

Firstly, remove all git repositories from Google Drive. Use GitHub or some other tool to keep backup.

Then to delete all desktop.ini files from you folder and all subfolders;

  1. Run CMD as administrator
  2. Navigate to the folder where the bad file is using cd
  3. Delete all "desktop.ini" files in the folder and all sub-folders using del desktop.ini /A:H /S
  4. Reload the git graph extension and the error should have gone
bangsluke
  • 11
  • 2
0

Git doesn't like the copious amounts of useless desktop.ini files created by Windows in Google Drive.

The best solution I've found so far is to search for desktop.ini in your project folder, select them all and delete. Then you can rerun the git commands without a problem.

I do this at the start of every day when running git pull and delete 300+ of them each time.

codeananda
  • 939
  • 1
  • 10
  • 16