How to copy commits from one branch to another?

前端 未结 9 1406
猫巷女王i
猫巷女王i 2020-11-27 09:08

I\'ve got two branches from my master:

  • v2.1: (version 2) I\'ve been working on for several months
  • wss: that I create
相关标签:
9条回答
  • 2020-11-27 09:29

    Use

    git cherry-pick <commit>
    

    to apply <commit> to your current branch.

    I myself would probably cross-check the commits I pick in gitk and cherry-pick them with right-clicks on the commit entry there instead.


    If you want to go more automatic (with all its dangers) and assuming all commits since yesterday happened on wss you could generate the list of commits using git log (with --pretty suggested by Jefromi)

    git log --reverse --since=yesterday --pretty=%H
    

    so everything together assuming you use bash

    for commit in $(git log --reverse --since=yesterday --pretty=%H);
    do
        git cherry-pick $commit
    done
    

    If something goes wrong here (there is a lot of potential) you are in trouble since this works on the live checkout, so either do manual cherry-picks or use rebase like suggested by Jefromi.

    0 讨论(0)
  • 2020-11-27 09:33

    Or if You are little less on the evangelist's side You can do a little ugly way I'm using. In deploy_template there are commits I want to copy on my master as branch deploy

    git branch deploy deploy_template
    git checkout deploy
    git rebase master
    

    This will create new branch deploy (I use -f to overwrite existing deploy branch) on deploy_template, then rebase this new branch onto master, leaving deploy_template untouched.

    0 讨论(0)
  • 2020-11-27 09:34

    For the simple case of just copying the last commit from branch wss to v2.1, you can simply grab the commit id (git log --oneline | head -n 1) and do:

    git checkout v2.1
    git merge <commit>
    
    0 讨论(0)
提交回复
热议问题