Reconstructing a reflog may not be as complicated as it was at the beginning. You can regenerate reflog in separate branches, or you can use git read-tree to create a single newbranch containing the reflog part.
One solution for each branch:
Suppose you need different branches for each commit. Copy your repository first. You are about to modify your reflog in this process so that you can also use the catchy version. Secondly, review your reflog and find the commit you want to start with. It will look like HEAD@ {n} . Suppose it was HEAD@ {49} . Then try the script, replacing head -50 with head -<n + 1> , whatever you do in your case:
#!/bin/sh reflog=$(git reflog | head -50 | awk '{ print $1 }') i=0 for ref in $reflog; do git checkout -B "reflog_$i" $ref i=$(expr $i + 1) done
This captures the reflog commit history once, and then repeats it, generating reflog_$i branches along the path. You can select, merge or manipulate them as you want. If it's just for presentation, you can write a short script that does a git checkout on branches, runs a test suite and shows all the greenery. Remember, reflog_1 is the most recent story; reflog_<n+1> is the oldest.
#!/bin/sh for i in $(seq 50 1); do git checkout "reflog_$i" ./test-suite.sh done
Throw it on the projector when you explain your fixing method, and this will be a pleasant backdrop.
If you want to merge all the branches, you can run this ruby script to apply them in order (or create an equivalent in any language convenient for you). Let me reiterate that you must have a backup of your directory because it is quite destructive.
#!/usr/bin/env ruby n = 50 n.downto 0 do |i| system " git read-tree reflog_#{i} git commit -m 'Refactoring #{n - i}' git checkout -- . git br -D refog_#{i} " end
Putting all commits on one branch using git read-tree
Copy the repository first. Then use the script as shown below. For the discussion in the first solution, change the two <n + 1> to whatever depth you want in your reflog, plus one. Pay attention to the additional channel on sed . You must use it or something like that so that reflog is applied to newbranch in reverse chronological order. Of course, this can be done without using both awk and sed , but this works:
#!/bin/sh reflog=$(git reflog | head -<n + 1> | awk '{ print $1 }' | sed -n '1!G;h;$p') git checkout -B newbranch HEAD@ {<n + 1>} for ref in $reflog; do git read-tree "$ref" git commit --no-verify -m "Adding commit $ref" git checkout -- . done
The end result will be newbranch , which should contain all the commits between HEAD@ {0} and HEAD@ {n} , based on commit HEAD@ {n+1} .