列出兩週內有人修改過的branches
$GIT_REPO_LOCATION="D:\workspace\git\Commons\"
cd $GIT_REPO_LOCATION
git for-each-ref --sort=-committerdate --format="%(refname:short), %(committerdate:iso8601), %(authorname)" refs/remotes/ |
ForEach-Object {
$line = $_ -split ', '
$date = [datetime]$line[1]
if ($date -ge (Get-Date).AddDays(-14)) {
Write-Output $_
}
}
pause
範例輸出:
origin/integration_testing, 2024-08-01 18:54:02 +0800, MJGood
origin/staging, 2024-08-01 18:54:02 +0800, MJBad
origin/supportCup, 2024-08-01 17:15:21 +0800, MJSmall
origin/master, 2024-08-01 12:17:08 +0800, MJBig
列出有哪些branch merge到staging
$localBranches = git branch --format="%(refname:short)" | Sort-Object
$remoteBranches = git branch -r --format="%(refname:short)" | ForEach-Object { $_.Replace('origin/', '') } | Sort-Object
$existingBranches = $localBranches + $remoteBranches | Sort-Object | Get-Unique
$mergedBranches = git log origin/staging --merges --pretty=format:"%s" --first-parent |
ForEach-Object {
if ($_ -match "Merge branch '([^']+)' into staging") {
$matches[1]
}
}
$validMergedBranches = $mergedBranches | Where-Object { $existingBranches -contains $_ }
$validMergedBranches | Sort-Object | Get-Unique
範例輸出:
supportCup
updateSUT
mjIsGood
強制reset master branch到remote master
git fetch --all
git checkout master
git reset --hard origin/master
留言
張貼留言