feat: completely rewrite GitHub mirror to create new history from target commit

BREAKING: This completely replaces the previous approach and will DELETE
all existing history on GitHub, creating entirely new commit SHAs.

Key changes:
- Use orphan branch instead of cherry-pick to break history connection
- Create initial commit from target commit tree using git read-tree
- Apply subsequent changes as completely new commits with new SHAs
- Force push will COMPLETELY REPLACE GitHub history
- No trace of commits before 7aca927937 will remain on GitHub

This ensures GitHub shows only history from the target commit onwards
with no connection to previous commits or their metadata.
This commit is contained in:
2025-07-20 22:30:57 +02:00
parent c7875102c5
commit febacb79ad
+66 -65
View File
@@ -31,7 +31,7 @@ jobs:
echo "Checking target commit exists:" echo "Checking target commit exists:"
git show --oneline 7aca927937 || echo "Target commit not found!" git show --oneline 7aca927937 || echo "Target commit not found!"
- name: Create filtered history from specific commit - name: Create completely new history from specific commit
run: | run: |
TARGET_COMMIT="7aca927937" TARGET_COMMIT="7aca927937"
@@ -46,66 +46,69 @@ jobs:
# Clean up any existing github-mirror branch # Clean up any existing github-mirror branch
git branch -D github-mirror || true git branch -D github-mirror || true
# Create a new branch starting from the target commit # Create a completely new orphan branch (no history)
git checkout -b github-mirror $TARGET_COMMIT git checkout --orphan github-mirror
echo "Created github-mirror branch from commit $TARGET_COMMIT" # Clear the staging area completely
echo "Current commit: $(git log --oneline -1)" git rm -rf . || true
# Get all commits from target commit to current main (excluding merge commits) # Get the file tree from the target commit and create initial commit
echo "Getting non-merge commits from $TARGET_COMMIT to main..." echo "Creating new history starting from $TARGET_COMMIT..."
COMMITS_TO_APPLY=$(git rev-list --reverse --no-merges $TARGET_COMMIT..main) git read-tree $TARGET_COMMIT
git commit -m "Initial commit - imported from $(git log --oneline -1 $TARGET_COMMIT)"
if [ -n "$COMMITS_TO_APPLY" ]; then echo "✅ Created new initial commit: $(git log --oneline -1)"
echo "Non-merge commits to apply:"
for commit in $COMMITS_TO_APPLY; do # Now get all commits after the target commit and apply their changes
git log --oneline -1 $commit COMMITS_AFTER_TARGET=$(git rev-list --reverse --no-merges $TARGET_COMMIT..main)
done
echo "" if [ -n "$COMMITS_AFTER_TARGET" ]; then
echo "📋 Applying changes from commits after $TARGET_COMMIT:"
# Apply all non-merge commits since the target commit for commit in $COMMITS_AFTER_TARGET; do
for commit in $COMMITS_TO_APPLY; do echo "Processing: $(git log --oneline -1 $commit)"
echo "Applying commit: $(git log --oneline -1 $commit)"
if git cherry-pick $commit; then # Get the commit message and author info
echo "✅ Successfully applied $commit" COMMIT_MSG=$(git log --format="%B" -n 1 $commit)
else COMMIT_AUTHOR=$(git log --format="%an <%ae>" -n 1 $commit)
echo "⚠️ Cherry-pick failed for $commit, trying to resolve..." COMMIT_DATE=$(git log --format="%ad" -n 1 $commit)
# Apply the changes from this commit
if git diff-tree --no-commit-id --name-only -r $commit | xargs -I {} git show $commit:{} > /dev/null 2>&1; then
# Apply file changes
git checkout $commit -- . || true
# Check if there are conflicts # Stage all changes
if git status --porcelain | grep -q "^UU\|^AA\|^DD"; then git add -A
echo "📝 Conflicts detected, trying to auto-resolve..."
# Only commit if there are changes
if ! git diff --cached --quiet; then
# Create new commit with original metadata but new SHA
GIT_AUTHOR_NAME=$(echo "$COMMIT_AUTHOR" | cut -d'<' -f1 | xargs)
GIT_AUTHOR_EMAIL=$(echo "$COMMIT_AUTHOR" | cut -d'<' -f2 | cut -d'>' -f1)
GIT_AUTHOR_DATE="$COMMIT_DATE"
# Try to resolve by taking the incoming changes export GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL GIT_AUTHOR_DATE
git add -A git commit -m "$COMMIT_MSG"
if git cherry-pick --continue; then echo "✅ Applied changes as new commit: $(git log --oneline -1)"
echo "✅ Resolved conflicts and continued"
else
echo "❌ Could not resolve conflicts, skipping commit $commit"
git cherry-pick --abort
continue
fi
else else
echo "❌ Cherry-pick failed for other reasons, skipping commit $commit" echo "⚠️ No changes to commit for $commit"
git cherry-pick --abort
continue
fi fi
else
echo "⚠️ Skipping problematic commit $commit"
fi fi
done done
echo "✅ Finished applying commits" echo "✅ Finished creating new history"
else else
echo "✅ No non-merge commits to apply - target commit is up to date with main" echo "✅ No commits after target commit - history starts fresh"
fi fi
# Show what merge commits were skipped echo ""
MERGE_COMMITS=$(git rev-list --merges $TARGET_COMMIT..main) echo "=== New History Summary ==="
if [ -n "$MERGE_COMMITS" ]; then echo "Total commits in new history: $(git rev-list --count github-mirror)"
echo "" echo "History starts with: $(git log --oneline --reverse | head -1)"
echo "📋 Merge commits that were skipped:" echo "Latest commit: $(git log --oneline -1)"
for commit in $MERGE_COMMITS; do
git log --oneline -1 $commit
done
fi
- name: Remove sensitive files and directories - name: Remove sensitive files and directories
run: | run: |
@@ -152,21 +155,17 @@ jobs:
echo "Final file structure (top level):" echo "Final file structure (top level):"
ls -la | head -10 || true ls -la | head -10 || true
- name: Verify clean history - name: Verify completely new history
run: | run: |
git checkout github-mirror git checkout github-mirror
echo "=== Final branch status ===" echo "=== Final History Verification ==="
echo "Total commits in github-mirror branch:" echo "Total commits in new github-mirror branch: $(git rev-list --count github-mirror)"
git rev-list --count github-mirror
echo "" echo ""
echo "Commit history (last 10):" echo "Complete commit history (should start from target commit content):"
git log --oneline -10 git log --oneline --reverse
echo "" echo ""
echo "Branch comparison with main:" echo "⚠️ Note: This is a completely NEW history with new commit SHAs"
echo "Non-merge commits in main not in github-mirror:" echo "🔍 Original target commit content preserved but with new commit ID"
git log --oneline --no-merges main..github-mirror || echo "None"
echo "Non-merge commits in github-mirror not in main:"
git log --oneline --no-merges github-mirror..main || echo "None"
- name: Check GitHub token - name: Check GitHub token
env: env:
@@ -179,7 +178,7 @@ jobs:
echo "GitHub token is available (length: ${#GITHUBTOKEN})" echo "GitHub token is available (length: ${#GITHUBTOKEN})"
fi fi
- name: Push to GitHub - name: Force push completely new history to GitHub
env: env:
GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }} GITHUBTOKEN: ${{ secrets.GITHUBTOKEN }}
run: | run: |
@@ -196,15 +195,17 @@ jobs:
echo "GitHub remote added:" echo "GitHub remote added:"
git remote -v git remote -v
# Force push the filtered branch to GitHub main # Force push the completely new history to GitHub main
echo "Pushing filtered history to GitHub..." echo "🔥 FORCE PUSHING completely new history to GitHub..."
echo "⚠️ This will COMPLETELY REPLACE all history on GitHub!"
git push github github-mirror:main --force git push github github-mirror:main --force
echo "✅ Push completed successfully!" echo "✅ Force push completed - GitHub now has completely new history!"
- name: Workflow completed - name: Workflow completed
run: | run: |
echo "✅ Mirror to GitHub workflow completed successfully!" echo "✅ Mirror to GitHub workflow completed successfully!"
echo "📊 History starts from commit: 7aca927937" echo "🔥 COMPLETE HISTORY REPLACEMENT: GitHub now has entirely new history"
echo "🔍 Check https://github.com/the-luap/picpeak to verify the mirror" echo "📊 History starts from commit content: 7aca927937"
echo "🔍 Check https://github.com/the-luap/picpeak to verify the new history"
echo "📈 Total commits pushed: $(git rev-list --count github-mirror)" echo "📈 Total commits pushed: $(git rev-list --count github-mirror)"
echo "🔀 Note: Merge commits were automatically filtered out" echo "🆕 All commit SHAs are NEW - no connection to previous history"