git-将另一个分支上的提交应用于工作副本 [英] git - apply a commit on another branch to the working copy

查看:110
本文介绍了git-将另一个分支上的提交应用于工作副本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我的提交具有有用的代码更改,但是在另一个分支上.

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?

我想分享的这与我之前的问题有关,但特定于工作副本: git cherry选择一个提交到另一个分支

Thought I'd share this is related to my previous question but specific to working copy: git cherry picking one commit to another branch

推荐答案

如何将所需的提交添加到不同的分支中.

git cherry-pick <SHA-1>...<SHA-1> --no-commit

在master分支的顶端应用由提交引起的更改,并使用此更改创建一个新的提交.

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

...的语法是提交范围.抓取从开始(排除)到最后一个的所有提交.如果您希望一次提交使用一次SHA-1

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

默认情况下git cherry-pick 提交,因此,如果您希望在不提交所有更改的情况下进行选择,只需添加-n标志

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 <hash>


cherry-pick合并提交

如果您需要选择合并而不是提交,请使用-m标志


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 <hash> to see a list of available parents
# 
git cherry-pick -m 1 <hash> 


阅读完整的 git cherry-pick 有关您可以使用的所有选项的文档


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

这篇关于git-将另一个分支上的提交应用于工作副本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆