To solve this, you can create a PowerShell script that gets all files inside the folder you want to execute the Git command, and iterate through all files running the Git command on each of them.
Here is some code I whipped up. Mind you, I did not test the code with the Git command, although it should work as is. Save the code above with a name of your choosing, for example: "AutoMergeMyFiles.ps1".
To execute it, you need to go to a PowerShell command window, and paste the path of this script file, following the parameters.
It should look like this:
C:\Users\YourName\Desktop\AutoMergeMyFiles.ps1 "folderpath of the files to be merged" "operation (ours / theirs)" and finally the file filter (eg: *.json)
Example: C:\Users\YourName\Desktop\AutoMergeMyFiles.ps1 "C:\GitFiles\MyProject" theirs *.json
param (
[parameter(Mandatory = $true)] [ValidateScript({
if ( -Not ($_ | Test-Path) ) {
throw "File or folder does not exist"
}
return $true
})]
[string]$mergePath,
[parameter(Mandatory = $true)] [ValidateSet("ours", "theirs")]
[string]$operation,
[parameter(Mandatory = $false)]
[string]$filter
)
$correctOperation = ""
if ($operation.ToString().Contains("ours") ) {
$correctOperation = "--ours"
}
elseif ($operation.ToString().Contains("theirs")) {
$correctOperation = "--theirs"
}
# Get-ChildItem -Path $mergePath -File -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -ExpandProperty FullName
# Get-ChildItem -Path $mergePath -Recurse -ErrorAction SilentlyContinue -Force
$files = Get-ChildItem -Path $mergePath -File -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -ExpandProperty FullName
if ($filter.Length -gt 0) {
$files = Get-ChildItem -Path $mergePath -Filter $filter -File -Recurse -ErrorAction SilentlyContinue -Force | Select-Object -ExpandProperty FullName
}
foreach ($file in $files) {
# Write-Output "git checkout $($correctOperation) $($file)"
git checkout $correctOperation $file
Start-Sleep -Milliseconds 150
}
Write-Output "Finished merging the files!"