So I have 3 branches: master
, suggestFix
and experimental
. suggestFix
points at the same place as master
because I want to use master
as a starting point to create pull request on GitHub. Experimental
has different commits, and I want to move to suggestFix
branch only some lines of code from experimental
.
I'll provide a concrete example. Here's final file on experimental branch:
And here are master and suggestFix branches:
I want my suggestFix branch to look like this after I do whatever is needed with git tools:
I don't care how history looks like as long as I can make a pull request and it will look like I modified master and got from master to suggestFix
with line insertions(as it usually shows in pull requests on GitHub).
I understand that I will need to review every single line of every single file and either accept or reject edits of lines or how they are also called hunks of code. That's what I want. I use a mix of Atlassian Sourcetree and MINGW64. I managed to start some kind of diff on Sourcetree:
But I don't understand how to do per-line patch and get to a file that I need(that you can see above on the third picture). Please help, I've been trying to do it for hours.
Here's a GitHub repository with that specific example:
So I have 3 branches: master, suggestFix and experimental. suggestFix points at the same place as master because I want to use master as a starting point to create pull request on GitHub. Experimental has different commits, and I want to move to suggestFix branch only some lines of code from experimental.
Answer to this is to switch to suggestFix branch, then run git merge experimental --squash
. This will squash all the commits from experimental into a single commit and stage them. So unstage all the changes first and then run git add --patch <filename>
to pick hunks of code you want to commit. Detailed explanation. Or you can more easily do it in a tool with UI like Sourcetree:
Then you just commit the changes you staged on the suggestFix branch. Then you can remove all unstaged changes with git reset --hard
.