问题
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 branch (not as another commit).
Is this possible? How would I do this?
Thought I'd share this is related to my previous question but specific to working copy: git cherry picking one commit to another branch
回答1:
How to add the desired commit(s) into different branches.
git cherry-pick <SHA-1>...<SHA-1> --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 use a single SHA-1
Read out the full git cherry-pick documentation for all the options you can use
回答2:
You can still use the git cherry-pick
command. See git cherry-pick --help
:
-n, --no-commit
Usually the command automatically creates a sequence of
commits. This flag applies the changes necessary to
cherry-pick each named commit to your working tree and the
index, without making any commit. In addition, when this
option is used, your index does not have to match the HEAD
commit. The cherry-pick is done against the beginning state
of your index.
So you can just git cherry-pick -n <commitid>
, and the changes will be applied to your working directory and staged in the index (like git -a
), but will not be committed.
来源:https://stackoverflow.com/questions/36778375/git-apply-a-commit-on-another-branch-to-the-working-copy