Monday, August 20, 2012

Recovering Git Projects from Time Machine

  • Recently I lost my development machine due to an upgrade to Mountain Lion. Sadly I had not backed up before performing the upgrade but I did backup before taking the machine to have its OS fixed. Even after three trips to the Apple Store's "Genius Bar" ... it continued to be an epic failure because recovering from the time machine backups yielded the same unusable experience once again.
  • I decided to recover the data piece by piece starting with my Git projects. I loaded the time machine file as a hard drive and copied the projects whole by dragging & dropping them into a similar file system location.
  • But when I performed a simple integrity check such as "git status" it led to messages like: "fatal: Not a git repository git repository"
  • Some basic searches led me to realize that I had to take a closer look at the .git directory in question:
  • First thing I realized was that my submodule that was causing trouble did not have a .git directory but had a .git file instead! Inside this file was a gitdir key and a path which redirected to a location in the parent git project.
    gitdir: /Users/olduser/gitProjects/myParentProject/.git/modules/myChildProjectModule
  • Afterwards, the solution was simple. The path for gitdir had an old username in it, which did not represent the current folder structure. Simply correcting the username in the path of the recovered file to the current one, fixed the issue.
    gitdir: /Users/currentUser/gitProjects/myParentProject/.git/modules/myChildProjectModule

0 comments:

Post a Comment