Created
October 16, 2025 00:19
-
-
Save mtlynch/f07ab1aa9911009d1d392a687de38b1f to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env bash | |
| # Script to replace git history with original repo history using rebase | |
| set -e # Exit on error | |
| readonly MAIN_BRANCH='main' | |
| # Using commit hash instead of tag v2.2.5 to avoid clobbering local tags with remote tags | |
| readonly LEGACY_COMMIT='b92ac00feff206cbb7d3e9e4b48c494d6fedb3bf' # corresponds to v2.2.5 tag | |
| # Step 1: Ensure we have the original repo as remote | |
| echo "" | |
| echo "Step 1: Checking for original repo remote..." | |
| if ! git remote | grep -q "jellyfin-legacy"; then | |
| echo "Adding jellyfin-legacy remote..." | |
| git remote add jellyfin-legacy https://github.com/jellyfin-archive/jellyfin-roku-legacy.git | |
| git fetch jellyfin-legacy "$LEGACY_COMMIT" | |
| echo "✓ Remote added and fetched" | |
| else | |
| echo "✓ Remote already exists" | |
| fi | |
| # Step 2: Get the initial commit hash from main branch | |
| echo "" | |
| echo "Step 2: Identifying initial commit to replace..." | |
| git checkout "$MAIN_BRANCH" | |
| INITIAL_COMMIT=$(git rev-list --max-parents=0 HEAD) | |
| echo "Initial commit to replace: $INITIAL_COMMIT" | |
| # Step 3: Create new branch from legacy commit | |
| echo "" | |
| echo "Step 3: Creating new branch from legacy commit (v2.2.5)..." | |
| # Delete new-history branch if it exists | |
| if git branch | grep -q "new-history"; then | |
| git branch -D new-history | |
| fi | |
| git checkout -b new-history "$LEGACY_COMMIT" | |
| echo "✓ New branch created from legacy commit" | |
| # Step 4: Rebase all commits after initial commit onto legacy commit | |
| echo "" | |
| echo "Step 4: Rebasing your commits onto legacy commit (v2.2.5)..." | |
| echo "This will replay all commits from $MAIN_BRANCH (excluding the initial commit)" | |
| echo "" | |
| # Use rebase --onto to rebase everything after INITIAL_COMMIT from MAIN_BRANCH onto current HEAD (legacy commit) | |
| git rebase --onto HEAD "$INITIAL_COMMIT" "$MAIN_BRANCH" | |
| echo "✓ Rebase completed successfully" | |
| # Step 5: Replace main branch | |
| echo "" | |
| echo "Step 5: Replacing $MAIN_BRANCH branch with new history..." | |
| git checkout -B "$MAIN_BRANCH" | |
| echo "✓ $MAIN_BRANCH branch updated with new history" | |
| # Step 6: Cleanup | |
| echo "" | |
| echo "Step 6: Cleaning up..." | |
| git branch -D new-history | |
| git remote remove jellyfin-legacy | |
| echo "✓ Cleanup complete" | |
| echo "" | |
| echo "=== Success! ===" | |
| echo "Your git history has been successfully replaced." | |
| echo "The legacy commit (v2.2.5) is now at the base of your repository." | |
| echo "" | |
| echo "Current branch: $(git branch --show-current)" | |
| echo "" | |
| echo "Next steps:" | |
| echo "1. Verify the history looks correct: git log --oneline" | |
| echo "2. If everything looks good, force push to remote: git push --force-with-lease origin $MAIN_BRANCH" | |
| echo "" | |
| echo "WARNING: This has rewritten history. Anyone who has cloned your repo" | |
| echo "will need to re-clone or reset their local copy." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment