如何在 git 中本地合并 master 和 fork?
我需要将 Active_admin 与 Formtastic 2 一起使用,但主分支尚不支持它。
几周前有人制作了一个分叉来支持 Formtastic 2 但随后其他添加内容被添加到主分支中,并且没有提交到分支。现在,fork 已经与其他东西一起过时了,但它仍然支持 Formtastic。
如何使用 git 将它们本地合并到我的计算机中?
I need to use Active_admin with Formtastic 2 and the main branch doesn't support it yet.
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. And now the fork is outdated with other things, but yet it support Formtastic.
How can I merge both of them locally in my computer using git?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
最简单的方法是切换到本地 formtastic 分支,然后运行 git merge master 来合并 master 分支更改(此后您可能需要处理冲突):
如果您希望历史记录成为更结构化一点,您可以改为变基:
变基将使您的历史记录更清晰,因为它的工作方式是它接受您在 formattastic 中所做的任何更改并缓存它们,然后合并来自 master 的新更改,然后重新播放您的 formattastic上面的变化。不过,这可能比简单地合并需要更多的工作(并且您必须查找变基以了解其工作原理)。
无论哪种方式,一旦所有内容都无冲突、经过测试并在分支中提交,那么您可以返回并将更改合并到 master 中,如下所示:
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):If you want your history to be a little more structured, you can rebase instead:
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. 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:
您需要向上游存储库添加新的远程引用,上游存储库是您分叉的原始存储库。请参阅:
然后您可以从
upstream
获取/拉取并更新您自己的本地分支。“如何清理我的 Github 分支以便我可以发出干净的拉取请求?”中解释了各种选项。
You need to add a new remote reference to your upstream repo, the upstream repo being the original repo you have forked. See:
Then you can fetch/pull from
upstream
and update your own local branch.The various options are explained in "How do I clean up my Github fork so I can make clean pull requests?".