Merging some parts of a different branch
I like Meld, which is a visual diff and merge tool.
Imagine I changed several parts of a file. Now I realize that some parts are good and should stay, while others should be removed again.
I am on a feature branch that was created from "main".
# Create a copy of the file
cp my-dir/my-file.xyz ~/tmp/
# restore the file to the original version
git restore -s main my-dir/my-file.xyz
meld my-dir/my-file.xyz ~/tmp/my-file.xyz
Now Meld opens and I can easily choose which parts I want to take into my branch, and which parts I don't need.
Imagine you created one PR containing several changes. Now you decide that you want to create three PRs instead.
First, create a backup of your branch:
git switch -c my-backup; git switch -
Create the branch for the first feature, create a copy of your whole directory, and switch the copy to main:
git switch -c feature-1
cd ..
cp -a myrepo myrepo-main
cd myrepo-main
git switch main
git pull
Now launch meld:
cd ..
meld myrepo-main myrepo
Now you can easily remove all changes that belong to feature-2 and feature-3.
I tried that with VS Code, but meld is more usable for this. You can copy files between both
directories with the context menu.
You can accept (click on arrow) or reject (shift-click) single changes.