简体   繁体   English

如何在git中本地合并master和fork?

[英]How do I merge locally a master and a fork in git?

I need to use Active_admin with Formtastic 2 and the main branch doesn't support it yet. 我需要将Active_admin与Formtastic 2一起使用,并且主分支尚不支持它。

A couple of weeks ago someone made a fork to support Formtastic 2 But then other additions were added to the master branch and were not commited to the fork. 几周前,有人制作了一个分叉来支持Formtastic 2,但是后来其他添加项添加到了master分支中,并且没有提交给该分叉。 And now the fork is outdated with other things, but yet it support Formtastic. 现在,前叉在其他方面已经过时了,但是它支持Formtastic。

How can I merge both of them locally in my computer using git? 如何使用git在我的计算机中本地合并它们?

This simplest way is to switch to your local formtastic branch, then run git merge master to merge the master branch changes in (you may have to deal with conflicts after that): 最简单的方法是切换到您本地的本地分支,然后运行git merge master来合并master分支中的更改(此后您可能必须处理冲突):

git branch formtastic
git merge master

If you want your history to be a little more structured, you can rebase instead: 如果您希望历史记录更加井井有条,则可以改组基准:

git branch formtastic
git rebase -i master

Rebasing will make your history cleaner because the way it works is it takes whatever changes you made in formtastic and caches them, then in merges in new changes from master, then it re-plays your formtastic changes on top. 变基将使您的历史记录更加整洁,因为它的工作方式是将您对formatic所做的任何更改都进行缓存,然后合并到master的新更改中,然后在顶部重新播放您的formastic更改。 This may take a little more work than simply merging though (and you'll have to look up rebasing to understand how it works). 但是,这可能比简单地合并要花更多的工作(并且您必须查找重新基准以了解其工作原理)。

Either way, once everything is conflict-free, tested, and committed in your branch, then you can go back and merge your changes into master like this: 无论哪种方式,一旦一切都没有冲突,经过测试并提交到您的分支中,则可以返回并将更改合并到master中,如下所示:

git branch master
git merge formtastic

You need to add a new remote reference to your upstream repo, the upstream repo being the original repo you have forked. 您需要向上游存储库添加新的远程引用,上游存储库是您已分叉的原始存储库。 See: 看到:

在此处输入图片说明

git remote add upstream https://github.com/gregbell/active_admin

Then you can fetch/pull from upstream and update your own local branch. 然后,您可以从upstream获取/拉取并更新自己的本地分支。
The various options are explained in " How do I clean up my Github fork so I can make clean pull requests? ". 如何清理Github叉,以便发出干净的拉取请求? ”中介绍了各种选项。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM