git cherry-pick to another branch

后端 未结 4 1104
深忆病人
深忆病人 2020-12-06 16:24

I wonder if there is the way to copy one commit to another branch without checking out that branch.

For example, I have two branches: master and p

4条回答
  •  天命终不由人
    2020-12-06 16:58

    Crazy idea (based on mnaoumov's comment) if you really want to avoid touching the checked out files (say you don't want to disturb your build system) … that's what I want anyway.

    1. Clone the whole git repo to a temporary directory.
    2. Do the work in the clone.
    3. Add the clone as a remote.
    4. git fetch clone && git branch mybranch clone/mybranch -f
    5. Clean up.

    This would be a thing to automate. If you have filesystem snapshots, cloning the whole repo is cheap – perhaps not so crazy after all…

提交回复
热议问题