用 Git 挑选提交意味着什么? [英] What does cherry-picking a commit with Git mean?

查看:27
本文介绍了用 Git 挑选提交意味着什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最近,我被要求 cherry-pick 提交.

Recently, I have been asked to cherry-pick a commit.

那么在 git 中挑选提交意味着什么?你是怎么做到的?

推荐答案

Git 中的 Cherry Picking 意味着从一个分支中选择一个提交并将其应用到另一个分支上.

Cherry picking in Git means to choose a commit from one branch and apply it onto another.

这与 mergerebase 等其他方式形成对比,这些方式通常将许多提交应用到另一个分支上.

This is in contrast with other ways such as merge and rebase which normally apply many commits onto another branch.

  1. 确保您位于要应用提交的分支上.

  1. Make sure you are on the branch you want to apply the commit to.

 git switch master

  • 执行以下操作:

  • Execute the following:

     git cherry-pick <commit-hash>
    

  • 注意:

    1. 如果你从公共分支挑选,你应该考虑使用

    1. If you cherry-pick from a public branch, you should consider using

     git cherry-pick -x <commit-hash>
    

    这将生成标准化的提交消息.这样,您(和您的同事)仍然可以跟踪提交的来源,并可能避免将来发生合并冲突.

    This will generate a standardized commit message. This way, you (and your co-workers) can still keep track of the origin of the commit and may avoid merge conflicts in the future.

    如果您在提交中附加了注释,则它们不会遵循优先顺序.要将它们也带过来,您必须使用:

    If you have notes attached to the commit they do not follow the cherry-pick. To bring them over as well, You have to use:

     git notes copy <from> <to>
    

    附加链接:

    这篇关于用 Git 挑选提交意味着什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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