One of my coworkers created a new git repository the "wrong" way, by copying the tree, deleting the .git
directory, and doing a new git init
. The coworker then dramatically slimmed down the repository, removing a bunch of files and renaming others (before committing anything).
It seems to me that it should be possible to restore the history by making a diff from the original repo to the new one, and then patching.
I was able to generate such a diff using
diff -ur old new --exclude=".git" > master.patch
I then almost got it to patch by doing
git clone old new_old
cd new_old
git checkout master
patch -p 1 < ../master.patch
# Then, if the patch command had worked, I would have done:
cd ..
rm -rf new
mv new_old new
(-p 1
tells it to chop off the repository directory name) but it seems to run into problems with files that were completely deleted.
I expect it'll also run into problems with files that have been renamed (e.g., from old_dog.hpp
to new_dog.hpp
). But I've also read that git
I'm sure someone else has done this before, but I can't find any examples. Is there a simple way to restore the history for files in this repository, or am I just wasting time?