Monban
Monban

Reputation: 546

Replaced /\t/ with / / on git repo

Was up too late last night working on some legacy code I inherited from someone else. In addition to putting the thing under revision control, I wanted to convert the codebase away from tabs to spaces. Ended up replacing all tab characters with two spaces in my working directory. Recursively. Including the .git directory. I had made some changes and committed them, but hadn't pushed the repo anywhere else yet.

It's not a huge loss if I just have to start the repo over again and squash changes so far into one commit, but supposing I was to put in the effort, how recoverable is this situation?

In a way I'm glad I made this mistake before I got too far in, but suppose it was the only copy of a years-long project, how screwed would you be?

Upvotes: 0

Views: 20

Answers (1)

CodeWizard
CodeWizard

Reputation: 142204

Recursively. Including the .git directory First you need to verify that your .git folder is not "broken".

# Verify that the .git folder and all the objects are still usable
git fsck --full

If you don't see and dangling data you are OK.

but hadn't pushed the repo anywhere else yet

You could still recover all the previous data even if you pushed (unless you did a forced push)


In a way I'm glad I made this mistake before I got too far in, but suppose it was the only copy of a years-long project, how screwed would you be?

If you don't have backup you will be in a HUGE trouble. its a recoverable situation but it will require a lot of work.


How to recover from this error?

If you have replaced all the tabs to spaces or vice versa you will have to try and replace them again, the good thing is that git has the SHA-1 which is the sha1sum of the content (the content itself is zipped and the format inside should not contain any spaces.

Is short (its a bit more complicated than this) git calculate the SHA-1 of the following content and compress it :

blob<space><content_lengt><null><content>

Then git compress the above content with zlib. So if you know how files are stored you can try to recover them buts its a lot of work. On the other hand there shouldn't be spaces in the content so the odds that you would have messed something inside (.git/object) is small.

Summary

Does not matter what you do never touch the .git folder !!!


enter image description here

Upvotes: 1

Related Questions