init: init commit
All checks were successful
Build and Deploy Quartz / build-and-deploy (push) Has been skipped
All checks were successful
Build and Deploy Quartz / build-and-deploy (push) Has been skipped
This commit is contained in:
47
scripts/clear-git-history.js
Normal file
47
scripts/clear-git-history.js
Normal file
@@ -0,0 +1,47 @@
|
||||
import { execSync } from "child_process"
|
||||
|
||||
function run(cmd) {
|
||||
try {
|
||||
console.log(`> ${cmd}`)
|
||||
execSync(cmd, { stdio: "inherit" })
|
||||
} catch (e) {
|
||||
console.error(`Error running: ${cmd}`)
|
||||
process.exit(1)
|
||||
}
|
||||
}
|
||||
|
||||
function main() {
|
||||
// Step 1: Create orphan branch
|
||||
run("git checkout --orphan temp-branch")
|
||||
|
||||
// Step 2: Add all files
|
||||
run("git add .")
|
||||
|
||||
// Step 3: Commit
|
||||
run('git commit -m "init: init commit"')
|
||||
|
||||
// Step 4: Rename current main to old
|
||||
run("git branch -m main old")
|
||||
|
||||
// Step 5: Rename temp-branch to main
|
||||
run("git branch -m temp-branch main")
|
||||
|
||||
// Step 6: Checkout main
|
||||
run("git checkout main")
|
||||
|
||||
// Step 7: Set upstream for main branch to origin/main
|
||||
run("git branch --set-upstream-to=origin/main main")
|
||||
|
||||
// Step 8: Set upstream for old branch to origin/old if it exists locally
|
||||
try {
|
||||
run("git show-ref --verify --quiet refs/heads/old")
|
||||
run("git branch --set-upstream-to=origin/old old")
|
||||
console.log("Upstream for 'old' branch set to origin/old.")
|
||||
} catch (e) {
|
||||
console.log("Local 'old' branch does not exist, skipping upstream setup.")
|
||||
}
|
||||
|
||||
console.log("Git history cleared and remote branches updated.")
|
||||
}
|
||||
|
||||
main()
|
||||
Reference in New Issue
Block a user