Чтобы объединить два последних коммита в Git, у вас есть несколько вариантов. Вот несколько методов с примерами кода:
Метод 1: использование Git Rebase
# Start interactive rebase
git rebase -i HEAD~2
# In the interactive rebase editor, change "pick" to "squash" for the second commit
# Save and close the editor
# Git will combine the two commits into one
Метод 2: использование Git Merge
# Create a new branch from the commit before the last two commits
git checkout -b merge_branch HEAD~2
# Merge the last two commits into the new branch
git merge --squash HEAD@{1}
# Commit the merged changes
git commit -m "Merge last two commits"
Метод 3: использование Git Reset и Commit
# Reset the branch to the commit before the last two commits
git reset HEAD~2
# Add the changes from the last two commits as staged changes
git add -A
# Commit the changes as a new commit
git commit -m "Merge last two commits"
Метод 4. Использование Git Cherry-pick
# Create a new branch from the commit before the last two commits
git checkout -b merge_branch HEAD~2
# Cherry-pick the last commit
git cherry-pick HEAD@{1}
# Cherry-pick the second-to-last commit
git cherry-pick HEAD@{1}
# Git will combine the two commits into one