How to merge latest changes from a base repo to a forked repo

不羁岁月 提交于 2020-01-06 14:03:24

问题


2 years ago I had forked a git repository. After that we made some changes on our side not much but we have changed little things in many files.

Now there are some fixes+features in base git repo from which we had forked. Since now we want to include those changes to our forked one, by keeping our local changes constant.

Is there any way to merge latest repo changes to our forked repo keeping our local changes as it is?


回答1:


If the changes are isolated onto their own branch, then you can simply pull the changes in from the upstream repository.

git pull

Mind you, this is equivalent to a git fetch && git merge operation.

If you want to include these new changes into your specific branch, you'll have to merge them in via git merge. Bear in mind, with changes to a code base from over two years old, you'll likely run into merge conflicts. At that point, you'll want to figure out what's changed from the old API to the new API and determine the best way to move forward.




回答2:


In addition to Makoto's answer which describes how to git merge the changes from the base repo branch into your forked branch, you could also consider doing a git rebase. Consider the following diagram:

base branch: A <- B <- C
your branch: A <- D <- E <- F

If you git rebase your branch on the base branch, then your branch would end up looking like this:

your branch: A <- B <- C <- D' <- E' <- F'

The rebase allowed you to pull in all the changes from the base branch, while essentially keeping the same commits you had on your branch intact, and in the same order you had made them over the past two years. I don't know if this is what you had in mind when you said "keeping our local changes as it is" but this might fit the bill.

You will also probably have merge conflicts here as you would with doing a merge, so get ready for some tedious fun.



来源:https://stackoverflow.com/questions/29092191/how-to-merge-latest-changes-from-a-base-repo-to-a-forked-repo

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!