[Engine-devel] backup/restore your git branch out of git repository

Eli Mesika emesika at redhat.com
Sun Jan 22 09:48:00 UTC 2012


Hi

I had last week a corrupted git repository caused possibly by a forced shutdown, I had to re-clone my repository to a new place and apply all my changes.
Lucky me , I had a backup out of the git repository.

The following takes 1 min to apply and may save you lot of work in case something gone wrong.


The following command will create a directory named as your current git branch under ~/backup/patch and will backup there all your branch work

copy the following lines to your ~/.bashrc

alias gitbackup='br=$(git symbolic-ref HEAD 2>/dev/null | cut -d "/" -f3);rm -f *.patch;git format-patch origin/master;mkdir -p ~/backup/patch/$br;mv *.patch ~/backup/patch/$br'

alias gitrestore='br=$(git symbolic-ref HEAD 2>/dev/null | cut -d "/" -f3);git stash; git checkout master;git checkout -b "$br-restore-$(date "+%d-%m-%y--%H-%M")";cp ~/backup/patch/$br/*.patch .;for f in $(ls -1 *.patch) ;do git am --ignore-whitespace $f;done'

> source ~/.bashrc

to backup your branch just run from your current git branch 

> gitbackup

In any case you have messed up with your branch (and you have a backup), you can run from your current git branch
> gitrestore

this will create a new restored branch named <your-original-branch-name>-restore-<date> and apply on it your backed up patches.





More information about the Engine-devel mailing list