How to merge a specific commit in Git

后端 未结 7 1332
攒了一身酷
攒了一身酷 2020-11-22 01:41

I have forked a branch from a repository in GitHub and committed something specific to me. Now I found the original repository had a good feature which was at HEAD

7条回答
  •  醉酒成梦
    2020-11-22 02:16

    'git cherry-pick' should be your answer here.

    Apply the change introduced by an existing commit.

    Do not forget to read bdonlan's answer about the consequence of cherry-picking in this post:
    "Pull all commits from a branch, push specified commits to another", where:

    A-----B------C
     \
      \
       D
    

    becomes:

    A-----B------C
     \
      \
       D-----C'
    

    The problem with this commit is that git considers commits to include all history before them

    Where C' has a different SHA-1 ID.
    Likewise, cherry picking a commit from one branch to another basically involves generating a patch, then applying it, thus losing history that way as well.

    This changing of commit IDs breaks git's merging functionality among other things (though if used sparingly there are heuristics that will paper over this).
    More importantly though, it ignores functional dependencies - if C actually used a function defined in B, you'll never know.

提交回复
热议问题