简体   繁体   中英

how can I git cherry-pick a commit from branch A to branch B but I am in branch master?

I need cherry-pick a commit from DEV to master, INT(for internal test environment), PROD branches.

If I need switch to corresponding branch every time cherry-pick, then I need checkout INT, checkout PROD.

Can I just be in branch Master and cherry-pick a commit from DEV to INT, to PROD but without checkout to any other branch?

Thanks a lot.

Not in general, no. Cherry-picking is implemented as a kind of merge internally, and merging—like most processes in Git—takes place on the current branch , so the branch must be checked out in a working tree, with an index in which the merge can happen.

You can, however, add a new working tree to any existing Git repository using git worktree add . This new working tree must be on some other branch: not the branch checked out in the main working tree, and not any branch checked out in any other working tree. 1 But that is exactly what you want here. So just add one working tree that's on branch INT —this becomes your second working tree—and a third one that's on branch PROD , and do the two cherry-pick operations in the two added working trees.


1 A working tree can also be in "detached HEAD" mode, but this doesn't help for your case.

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