使用GIT,如何选择性地将一次提交中的更改合并到另一个"fork"中? [英] Using GIT, how can I selectively merge changes from one commit on another 'fork'?

查看:128
本文介绍了使用GIT,如何选择性地将一次提交中的更改合并到另一个"fork"中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

采取这种情况:

  1. 我决定在github.com上分叉"一个代码库,并开始执行我的例程:编辑-提交-推送;又名hack hack hack.
  2. 进行一些更改后,我看到另一个人对同一项目进行了更改,我喜欢它们!
  3. 我决定要将它们合并到我的文档中.问题是,我只想要一个特定提交中的一部分",他已经做出了几次提交.

将这些选定数量的更改合并到我的叉子"中,最有效的方法是什么?

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

推荐答案

在掀起IRC世界的热潮之后,有人提出了一个很好的解决方案:

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!

好的,也许不是那么简单.这是完整的步骤:

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

  1. 首先,您必须在您的存储库中,进行必要的cd -ing才能进入您的工作目录.

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

您现在需要添加远程分支,然后将其提取.通过以下方式做到这一点:

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

您现在可以运行诸如git log someUser/master之类的命令,以查找要部分合并的提交SHA1.

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

一旦有了SHA,就可以运行:

Once you have the SHA, you can now run:

git cherry-pick -n SHA1

其中SHA1是提交SHA,du!

where SHA1 is the commit SHA, duh!

根据提交的年龄以及项目的特定区域更改的频率,很可能会发生冲突.抱歉,但是您必须使用值得信赖的编辑器手动解决这些问题.因此,请拔出VIM或您使用的任何其他工具,然后摆脱冲突,直到达到您喜欢更改的阶段.

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.

您现在必须将索引重置为HEAD版本,然后可以使用可信任的GIT add --patch命令来选择所需的更改:

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 --patchgit add -p

是的!提交时间:

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

要清理混乱(您在git add --patch中拒绝的内容)并仅将选定的更改保留在工作存储库中,请运行:

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

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

Apparently git checkout -f is another option as well.

这篇关于使用GIT,如何选择性地将一次提交中的更改合并到另一个"fork"中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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