的背后| ADO 分支視圖的Ahead非常有用,可以一目了然地查看其中是否有任何實作的功能develop需要合并到main. 合并develop到 時main,我們使用合并提交(無快進)來允許 GitVersion 自動碰撞我們工具的次要 SemVer 版本。因此main總是領先于develop越來越多的合并提交。然而,這些合并提交從不包含任何檔案更改。
我還想一目了然地查看是否有任何檔案更改需要從mainto合并回develop(例如,修補程式)。
我如何確保開發人員記得將修補程式從 合并回main到develop?

uj5u.com熱心網友回復:
為此,我在Visual Studio 開發人員社區上創建了一張票。
作為一種解決方法,我目前使用夜間管道來檢查是否僅通過合并提交main領先develop。這樣,開發人員記得將修補程式合并回develop.
schedules:
- cron: "45 1 * * Mon,Tue,Wed,Thu,Fri"
branches:
include:
- main
steps:
- task: PowerShell@2
displayName: Check develop ahead of main
inputs:
filePath: check-develop-ahead-of-main.ps1
# check-develop-ahead-of-main.ps1
$commitHashes = git rev-list --left-right origin/develop..origin/main | %{ $_.Substring(1, 6)};
foreach ($commitHash in $commitHashes) {
$parentCommits = (git show --no-patch --format="%P" $commitHash).Split(" ");
$isMergeCommit = $parentCommits.Count -ne 1;
if (!$isMergeCommit) {
throw "There is at least one commit ($($commitHash)) that is on the main branch but NOT on the develop branch. Please create a pull request from main to develop."
}
}
Write-Host "The main branch is only ahead of the develop branch by merge commits ($($commitHashes))." -ForegroundColor Green
uj5u.com熱心網友回復:
我還想一目了然,是否有任何檔案更改需要從 main 合并回開發(例如修補程式)。
完成此操作的一種方法是使用此單個命令:
git diff origin/develop...origin/main --name-only
請注意,那里有3 個點,(專門用于git diff)的意思是“顯示僅在 上的更改main”。
如果你沒有得到任何輸出,那么你只有在main. 如果您在輸出中列出了一個或多個檔案,那么您需要將一些更改合并回develop.
請注意,該--name-only標志僅列出檔案而不是這些檔案的完整差異,但它完全是可選的。我想我更希望您的用例只得到“是或否”的答案。
關于點的旁注:點符號在 Git 中有點令人困惑。使用git diff,如果您使用 2 個點而不是 3 個點,您將獲得兩個分支的完整差異。這與 2 和 3 個點的含義相反git log。在 中git log,兩個點是“僅在右側向我顯示新提交”,而三個點是“在任一側向我顯示新提交”。
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/313216.html
標籤:混帐 电源外壳 azure-devops 天蓝色管道
