Skip to content

Instantly share code, notes, and snippets.

@hoangitk
Created June 18, 2026 07:17
Show Gist options
  • Select an option

  • Save hoangitk/c07dfa5667e1fa7b2355861bbf12a1c9 to your computer and use it in GitHub Desktop.

Select an option

Save hoangitk/c07dfa5667e1fa7b2355861bbf12a1c9 to your computer and use it in GitHub Desktop.
[Git truncate 2 months history] #git #tip
  • Git truncate 2 months history

    This is only use for Release repo

    • Fetch 2 months ago:
    git fetch --shallow-since="2 month ago"
    • Get oldest commit available
    git log --oneline
    • Start a Fresh Temporary Branch
    git checkout --orphan temp-branch <commit-hash>
    • Save the Base State
    git add -A
    git commit -m "New repo start: 2 months ago"
    • Replay the Rest of the Month
    git cherry-pick <commit-hash>..main
    • Switch Branches Locally
    git branch -D main
    git branch -m main
    • Force-Push to the Remote Server
    git push origin main --force
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment