Pete's Log: Filling in the historical record (a.k.a. git shenanigans)

Entry #2070, (Meta)
(posted when I was 43 years old.)

This falls somewhere in the intersection of "why didn't I do this a long time ago" and "why am I spending time on this."

The oldest copy of Pete's Log code I still have dates to September of 2003. I also have a few more snapshots since then that all predate tracking changes in git. So last night I had some fun with git and now the "oldest" commit on my tree is dated 19 years ago. This pleases me.

It's fun to look at the evolution. Pete's Log in 2003 was already pretty full-featured, but a lot has changed since then. In most files, git blame will only pick out the occasional <? or } or empty line as coming from that commit, but a few places still come through. For example the form on the search page is largely unchanged since 2003. (The processing of the form, however, is not.)

I haven't often strayed from more mainstream git usage, so I'm not sure this was the best way of accomplishing this. But it was a fun learning exercise and for future reference, here's what I did:

  1. Created an empty branch with no parent

    git checkout --orphan histbranch git rm -rf .

  2. Copied in the 2003 code
  3. Faked out the commit date and committed

    GIT_COMMITTER_DATE="2003-09-27T00:00:00" GIT_AUTHOR_DATE="2003-09-27T00:00:00" git commit

  4. Repeated steps 2 and 3 for the other snapshots of the code I had
  5. Checked out the first commit to the main branch and committed those files to my history branch (to avoid conflicts in the coming rebase)
  6. Made a copy of my main branch

    git checkout main git checkout -b rebase_main

  7. Rebased this copy of main onto my history branch, effectively telling it that's where it came from

    git rebase histbranch

  8. Made sure there were no conflicts and everything looked right
  9. Backup the old main and then reset to the rebased main

    git checkout main git branch main_old git reset --hard rebase_main

At this point I was able to confirm via git log that the history looked right. I then thought I ran into trouble when trying to push the changes because I was getting the error "Updates were rejected because the tip of your current branch is behind its remote counterpart." The correct fix to that turned out to be simple, just git push -f origin main to force the push. I guess that can happen when rebasing, since my copy was now based on an entirely new history compared to the origin.

Thanks in part to Guildencrantz's answer on StackOverflow for getting me started with this.