Created
May 10, 2023 13:35
-
-
Save azurekid/c5ff1e16729afd93b24413adf1abe009 to your computer and use it in GitHub Desktop.
This file contains 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
[CmdletBinding()] | |
param ( | |
[Parameter(Mandatory = $true)] | |
[string]$GitBranch, | |
[Parameter(Mandatory = $false)] | |
[string]$CommitMessage = 'rebuild repository', | |
[Parameter(Mandatory = $false)] | |
[switch]$Force | |
) | |
Write-Host "USAGE OF THIS SCRIPT IS ON YOUR OWN RISK" -ForegroundColor 'Red' | |
Write-Host "- I AM NOT RESPONSIBLE FOR ANY LOSS OF DATA-" -ForegroundColor 'Red' | |
if ($Force) { | |
Write-Host "[-] Checking out current branch" -ForegroundColor 'Yellow' | |
git checkout --orphan (new-guid).guid | |
Write-Host "[-] Adding current files" -ForegroundColor 'Yellow' | |
git add . | |
Write-Host "[-] Adding commit message [$CommitMessage]" -ForegroundColor 'Yellow' | |
$null = git commit -m $CommitMessage | |
Write-Host "[-] Deleting current branch with the name [$GitBranch]" -ForegroundColor 'Red' | |
Write-Host "[-] To late now, branch [$GitBranch] is deleted" -ForegroundColor 'Red' | |
$null = git branch -D main | |
Write-Host "[-] Renaming branch to [$GitBranch]" -ForegroundColor 'Yellow' | |
$null = git branch -m main | |
Write-Host "pushing data to new branch" -ForegroundColor 'Yellow' | |
$null = git push -f origin $GitBranch | |
} else { | |
Write-Error "Use the '-Force' switch start use the function! 'Clear-GitHistory -GitBranch main -Force'" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment