I’m a newbie to git, and I do understand how git cherry-pick works, but here is my problem:
Recently, someone in my team, changed the directory structure in master, but not the directory structure in another branch.
Now, when I do make changes to my code in branch, I want to bring them (cherry-pick) into master. This was fine until the directory structures in both master and the branch were same.
topDir/some/subdir/file — master
topDir/some/other/subdir/file — branch
file, whose changes are to be brought into master is the same, but not the directory structure it is contained in. When I try to do a cherry-pick the usual way, I get an error along the lines of:
git checkout master
git cherry-pick commit
error: pathspec topDir/some/other/subdir/file does not exist
Now, what is the best way to go about cherry-picking in this scenario? Any pointers are highly appreciated.
OK. I just noticed that, in the same scenario, when I do a cherry-pick, git is smart enough to actually pick one of the files correctly from the commit, but does not recognize the other.
To use the same example I mentioned in my original post: In the same commit,
topDir/some/subdir/file1,
topDir/some/subdir1/file2.
I go to master, which has “file1” and “file2”, just in a different dir structure:
topDir/src/some/subdir/file1
topDir/src/some/subdir1/file2.
Now, if I do a cherry-pick, git is intelligent enough to pick up the changes in file1, even though this is in a different dir structure, but doesn’t pick up the changes for file2. Any pointers? If anyone wants me to be more clear, I’ll be happy to.
So, what I did to workaround the problem was do a cherry-pick, manually change the one git did not pick up, and “git commit -C .
Happy to help 🙂 if the one in master will be the permanent way, I would fix the file structure in the topic branch to match master, commit to the branch, *then merge the changes into master, not cherry-pick. As in
Really though, it depends on what the use cases of the files are, and what you want to be in the master branch, which is much more a your company specific question, not so much a technical problem anyone here can answer for you 😉