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

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

问题描述

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

我想将另一个分支中的这个提交应用到我当前分支上的工作副本(而不是另一个提交).

这可能吗?我该怎么做?

我想分享这与我之前的问题有关,但特定于工作副本:


cherry-pick 无需提交

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

这将允许您查看更改并根据需要手动提交或在遇到太多冲突时中止更改.

git cherry-pick -n 


cherry-pick 合并提交

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

<代码>## 在这种情况下,我们选择提交中的 [1] 第一个父级# 使用 git show <hash>查看可用父母的列表#gitcherry-pick -m 1 <hash>


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

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

解决方案

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


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> 


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

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

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