Git Partial Merge
I was previously working on a separate branch branch-tmp, now I want to merge some files in that branch into my main personal branch chengdol_master, and finally create a pull request to merge int master.
Resource
Git tip: How to “merge” specific files from another branch Interactive merge
Solution
Notice that in my case, the target files in
branch-tmpare completely applicable forchengdol_master, so I just want to overwrite corresponding files inchengdol_master. If we need to pick some changes and leave others in the file, do aninteractive merge, run this fromchengdol_master:
1 | git checkout --patch brach-tmp <relative path to target file> |
First check if you have origin/branch-tmp locally
1 | git branch -r | grep branch-tmp |
If not, you need to fetch it alone or fetch all origin branches:
1 | git fetch origin branch-tmp |
Then go to your target branch chengdol_master, use git checkout command to do the job:
1 | git checkout origin/branch-tmp <relative path to target file> |
then the merged files from branch-tmp are in staging phase, you can directly commit or unstage them in the chengdol_master branch, then push and handle the pull request.