I have a master branch 'A' and a feature branch 'B'.
Now a file called 'X' has evolved with some changes in both 'A' and 'B' branches.
How do I create a third branch 'C' ( From Master 'A') where I can get the file 'X', having both the changes from branch 'A' and branch 'B'. And also I don't need other commit changes from 'B'. I need only the change of file 'X' from 'B'.
What I tried?
git cherrypick - This didn't work because of file 'X' in branch 'B' has hundreds of commits associated with it. It's pretty hard to cherrypick and also sometimes it might bring changes involved in other files.
git checkout C && git checkout 'branch B' -- path_of_X I created a branch 'C' from master branch 'A' and tried to checkout file 'X' from branch 'B'. Now All my changes of file 'X' from 'A' has vanished. Also, the git history for the file 'X' is lost.
git checkout C && git merge B --no-commit --no-ff I created a branch 'C' from master branch 'A' and merged branch 'B' completely with --no-commit and -no-ff options. This has brought all the changes from 'B'. Now I tried to discard all changes in 'C' from 'B' except the changes of file 'X'. Looks like there is no way to do a git discard excluding a file/folder.
What is the way to solve this problem? Any help would be much appreciated. Thanks in advance.