forked from Azure/PyRIT
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsquash_commits.ps1
29 lines (22 loc) · 885 Bytes
/
squash_commits.ps1
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
param(
[string]$CommitMessage,
[string]$fork
)
$mainBranch = 'main'
$featureBranch = git rev-parse --abbrev-ref HEAD
git fetch origin $mainBranch
# Check out the feature branch (though you should already be on it)
git checkout $featureBranch
git rebase -i origin/$mainBranch
# Squash commits
# Note: The interactive rebase '-i' will open an editor to squash commits manually
# Replace 'pick' with 'squash' beside all but the first commit to combine them
# If you're not comfortable with the interactive mode or want to automate:
# Assuming you want to squash all commits made on the feature branch since it diverged from main:
$commitCount = (git rev-list --count HEAD ^origin/$mainBranch)
if ($commitCount -gt 1) {
git reset --soft "HEAD~$commitCount"
git commit -m $CommitMessage
}
# Push changes to the remote repository
git push $fork $featureBranch --force