简体   繁体   中英

Git Cherry-Pick

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

git checkout branch
mv other/subdir/file subdir/file
git status
// git add and git rm to get the commit proper
git commit -m "fixing file struct"
git checkout master
git merge branch

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 ;)

Suppose we have A,B,C,D,E & F nodes. The user is currently on F node and want to cherry pick with C node by using type git command like Git Cherry-Pick C then this command apply C node to F node.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM