Files
scripts/git/git combine multiple commits.md
Dobromir Popov dc2af0386d local changes DEV
2024-04-08 12:36:16 +03:00

81 lines
2.9 KiB
Markdown

<!-- Create a New Branch for Review: -->
git checkout -b review-branch
<!-- find latest hash's parent -->
oldest_commit_hash=$(git log --grep="GAT-4861" --reverse --format="%H" | head -1)
git checkout -b review-branch $oldest_commit_hash^
<!-- PS -->
$oldestCommitHash = git log --grep="GAT-4861" --reverse --format="%H" | Select-Object -First 1
git checkout -b review-branch $oldestCommitHash^
<!-- LINUIX Cherry-Pick Commits Based on Log Search -->
git log --grep="GAT-4861" --format="%H" | xargs -L1 git cherry-pick
<!-- //windows -->
git log --grep="GAT-4861" --format="%H" | ForEach-Object { git cherry-pick $_ }
<!-- forced -->
git log --grep="GAT-4861" --format="%H" | ForEach-Object {
git cherry-pick $_ --strategy-option theirs
}
git log --reverse --grep="GAT-4861" --format="%H" | ForEach-Object {
git cherry-pick $_ --strategy-option theirs
}
<!-- forced new oldest first -->
git log master --reverse --grep="GAT-4861" --format="%H" | ForEach-Object {
git cherry-pick $_ --strategy-option theirs --no-commit
if ($LASTEXITCODE -ne 0) {
Write-Host "Conflict encountered. Skipping commit $_"
git reset --merge
}
}
<!-- Cleanup -->
git checkout master # Replace 'main' with your default branch name if different
git branch -D review-branch
<!-- did not work as we need to store commit hashes before we checkout oldest hash -->
git checkout master # Replace 'main' with your default branch name if different
git branch -D review-branch
$oldestCommitHash = git log --grep="GAT-4861" --reverse --format="%H" | Select-Object -First 1
git checkout -b review-branch $oldestCommitHash^
git log master --reverse --grep="GAT-4861" --format="%H" | ForEach-Object {
git cherry-pick $_ --strategy-option theirs --no-commit
if ($LASTEXITCODE -ne 0) {
Write-Host "Conflict encountered. Skipping commit $_"
git reset --merge
}
}
<!-- try ising patch
Create a Diff Patch for the Commits
This command finds the first and last commits with "GAT-4861" and generates a diff patch between these points.
tail -n 1 and head -n 1 are used to get the earliest and latest commit hashes respectively.
The ^ after the first commit hash indicates the parent of that commit.
The diff is saved in a file named changes.patch. -->
git diff $(git log --grep="GAT-4861" --format="%H" | tail -n 1)^ $(git log --grep="GAT-4861" --format="%H" | head -n 1) > changes.patch
<!-- WIN/PS -->
$firstCommit = git log --grep="GAT-4861" --reverse --format="%H" | Select-Object -First 1
$lastCommit = git log --grep="GAT-4861" --format="%H" | Select-Object -First 1
git diff $firstCommit^ $lastCommit > changes.patch
<!-- Apply the Patch to a New Branch -->
# Checkout to the parent of the earliest "GAT-4861" commit
$earliestCommitHash = git log --grep="GAT-4861" --reverse --format="%H" | Select-Object -First 1
git checkout -b review-branch $earliestCommitHash^
# Apply the patch
git apply changes.patch