blog.minskio.co.uk

Content and theme behind minskio.co.uk
Log | Files | Refs

recovering-deduplicated-git-repositories.md (1558B)


      1 ---
      2 title: "Recoving de-duplicated git repositories"
      3 date: 2022-05-05T15:37:00
      4 tags: ["Linux", "Recovery", "Snippets", "Software"]
      5 ---
      6 
      7 I have a number of software projects in a single directory, using `git` for version control which is shared across most of my computers using `syncthing`.
      8 
      9 Late one night, I wanted to de-duplicate a folder full of files I'd been working on over the course of a few weeks. I'd work through a directory then as part of my 'completing' the work, would de-duplicate it using `jdupes` to ensure no files were duplicated. I'm sure you can see where this is going.
     10 
     11 As part of my workflow, I was navigating directories, tapping the up arrow to repeat my last command and hitting enter with reckless abandon. I noted the command took a little longer than usual and immediately realised what I'd done. I went to assess the damage, when browsing using git, cgit, or even the github desktop client, all my repositories were broken except for a single bare repository.
     12 
     13 The first thing to do is to find any potentially affected directories. This can simply be done via `find . -type d -name '.git'`. As what was deleted will only ever be duplicated content, you should be able to rebuild these repositories quite easily with the following:
     14 
     15 ```
     16 cd affected-project
     17 mv ".git" ".gitcontents"
     18 git init
     19 rsync --remove-source-files -av ".gitcontents" ".git"
     20 find ".gitcontents" -empty -delete
     21 ```
     22 
     23 Which should get you up and working again.
     24 
     25 The moral of the story is to keep a backup, and then make a backup of your backup (just in case).