使用GIT,我怎样才能有选择地从别人的“叉子”中拉出/合并变化? [英] Using GIT, how can I selectively pull / merge changes from another's 'fork'?

查看:101
本文介绍了使用GIT,我怎样才能有选择地从别人的“叉子”中拉出/合并变化?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下情景:


  1. 我决定在github.com上'分支'一个代码库,并开始执行我的例程:编辑 - 提交 - 推送; aka hack hack。

  2. 在我做了一些修改后,我发现另一个人在同一个项目上做了一些改变,我喜欢他们!

  3. 我决定我想将它们合并到我的。问题是,我只想要一个特定提交的'部分',他提出了几个提交。

什么是最有效的方法来获取这些选择的变化量,并入我的'叉'?

解决方案

世界上,有人给出了一个很好的解决方案:

  git cherry-pick SHA1  - 不提交
git add - 补丁

希望这可以帮助其他人解决相同的问题!



编辑:好的,也许它不是那么简单。以下是完整的步骤:首先,您必须在您的存储库中,执行必要的操作 cd -ing到您的工作目录。
现在需要添加远程分支,然后获取它。通过这样做:



git remote add someUser git://github.com/someUser/someRepo.git



git fetch someUser


  • 现在运行诸如 git log someUser / master 之类的命令来查找您希望在部分中合并的提交SHA1。


  • 一旦你有了SHA,你现在可以运行:

    git cherry-pick -n SHA1



    其中 SHA1 是提交SHA,duh!


  • 很可能会有冲突,具体取决于提交的年龄,以及项目特定区域多久改变一次。对不起,您必须使用可靠的编辑器手动解决这些问题。因此,请拔出VIM或其他任何您使用的内容,然后彻底解决冲突,直到您进入喜欢这些更改的阶段。

  • 您现在拥有将索引重置为HEAD修订版,然后您可以使用可信的GIT add --patch 命令来挑选您想要的更改:



    $ git reset HEAD



    git add - 补丁 git add -p


  • 提交时间:

    git commit -m我合并了一定数量的更改


  • 清理乱糟糟的东西(你在 git add --patch 中说不的东西),只保留所选的更改在您的工作仓库中运行:

    git reset --hard HEAD



    显然 git checkout -f 也是另一种选择。


    Take this scenario:

    1. I decide to 'fork' a codebase on github.com, and start doing my routine: Edit - Commit - Push; aka hack hack hack.
    2. After I made some changes, I see some changes another person has made on the same project, and I like them!
    3. I decide I want to merge them into mine. Problem is, I only want a 'portion' of one particular commit, out of several commits he has made.

    What would be the most efficient method of getting these select amount of changes, merged into my 'fork'?

    解决方案

    After trolling the waves of the IRC world, someone gave a great solution:

    git cherry-pick SHA1 --no-commit
    git add --patch
    

    Hopefully that helps anyone else with the same question!

    EDIT: OK, maybe it isn't quite that simple. Here are the full steps:

    1. First you have to be in your repository, do the necessary cd-ing to get to your working directory.

    2. You now need to add the remote branch, and then fetch it. Do this by:

      git remote add someUser git://github.com/someUser/someRepo.git

      git fetch someUser

    3. You can now run commands such as git log someUser/master to find the commit SHA1 you want to merge in 'partially'.

    4. Once you have the SHA, you can now run:

      git cherry-pick -n SHA1

      where SHA1 is the commit SHA, duh!

    5. There quite possibly will be conflicts, depending how old the commit is, and how often that particular area of the project changes. Sorry, but you have to manually resolve these with your trusty editor. So pull out VIM, or whatever else you use, and hack away at the conflicts until you get to the stage where you like the changes.

    6. You now have to reset the index to the HEAD revision, then you can then use the trusty GIT add --patch command to pick and choose what changes you want:

      git reset HEAD

      git add --patch or git add -p

    7. Yay! Commit time:

      git commit -m "I merged a select amount of changes"

    8. To clean up the mess (The stuff you said no to in git add --patch) and only keep the selected changes in your working repository, run:

      git reset --hard HEAD

      Apparently git checkout -f is another option as well.

    这篇关于使用GIT,我怎样才能有选择地从别人的“叉子”中拉出/合并变化?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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