如何合并单个提交? [英] How do I merge a single commit?

查看:102
本文介绍了如何合并单个提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有时我一次与多个分支机构合作.假设我有称为master,1.1版和实验版的分支.我创建了一个新文件或进行了实验性更改,但我希望一个更改可以应用于其他分支.

Sometimes I'm working with several branches at once. Say I have branches called master, release-1.1, and experimental. I create a new file or make a change in experimental and I want that one single change to apply to the other branches.

我可以在git中执行此操作吗?如果我只是简单地将提交合并到另一个分支中,则git会自动快进"并包括其间的所有提交.但是必须有某种方法来处理此用例.

Can I do this in git? If I simply merge the commit into another branch, git automatically "fast-forwards" and includes any commits in between. But there must be some way to handle this use case.

推荐答案

您要执行的操作称为

What you want to do is called cherry picking. You can cherry pick a single commit using the following command:

$ git cherry-pick <commit hash or name>

这会将对 only 所做的更改合并到您当前的分支中.但是请注意,这会创建一个 new 提交;这个新的提交与樱桃挑选的提交具有完全相同的更改(甚至是相同的提交日期和作者),但是从技术上讲,它是一个 new 提交,因此您将其视为一个新的提交在例如gitk中.您还必须为每个要查看更改的分支执行樱桃选择.

This will incorporate the change from that commit only into your current branch. Note, however, that this creates a new commit; this new commit has the exact same changes as the cherry-picked commit (and even the same commit date and author), but it is technically a new commit, so you'll see it as a new commit in, e.g., gitk. You'll also have to perform the cherry pick for each branch in which you want to see the change.

这篇关于如何合并单个提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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