git - apply a commit on another branch to the working copy

后端 未结 2 1518
[愿得一人]
[愿得一人] 2020-12-13 01:22

so I have a commit that has a helpful code change, but on another branch.

I would like to apply this commit in the other branch to my working copy on my current bran

2条回答
  •  心在旅途
    2020-12-13 01:59

    How to add the desired commit(s) into different branches.

    git cherry-pick ... --no-commit

    Apply the change introduced by the commit(s) at the tip of the master branch and create a new commit(s) with this change.

    The syntax of the ... is a commit range. grab all commits from start (exclude) to the last one. If you want a single commit to use a single SHA-1


    cherry-pick without commiting

    By default git cherry-pick commit your changes, so if you wish to cherry-pick without committing all the changes simply add the -n flag

    This will allow you to review the changes and commit them manually if you wish or abort it if you run into too many conflicts.

    git cherry-pick -n 
    

    cherry-pick a merge commit

    In case you needed to cherry-pick a merge instead of a commit, use the -m flag

    #
    # In this case, we select the [1] first parent in the commit
    # Use git show  to see a list of available parents
    # 
    git cherry-pick -m 1  
    

    Read out the full git cherry-pick documentation for all the options you can use

提交回复
热议问题