简体   繁体   中英

How to merge code after prettify ran upstream

I'm maintaining a fork of an open source project where we pull approximately every month from upstream in order not to branch too much.

When I tried to pull from upstream this month I found out they ran prettify (or some other equivalent) over the entire code (~15,000 files) and virtually every change we've made in our fork since the last pull (and there were quite a lot) causes conflicts.

Anyone ever ran into this issue? Would appreciate any help if there's any way to merge this faster than manually 3-way merging every file.

Thank you.

EDIT: I do not have write access to the upstream project, from my perspective it's read only.

If it is a tool you have acess to, the way with the least effort (and losing history) would be:

# checkout the last revision that you merged from upstream _before_ the beautifying process was run in upstream
# run the tool on that revision
git checkout -b the-temp-branch
git commit -m "beautifying base revision"
# now we will create from thing air a revision that has this revision and the tip of the upstream branch as parents, content will be the same as the beautified upstream branch
git commit-tree -p HEAD -p the-upstream-branch -m "merging upstream branch" the-upstream-branch^{tree}
# that command will print an id when you run it... say that ID is XXXX
# set the temp branch over there
git branch -f the-temp-branch XXXX
# go to the tip of your downstream branch
# run the tool
git reset --soft the-temp-branch~
git commit -m "all our changes in a single shot"
# now you can merge the-temp-branch and get all upstream changes... there should not be that many conflics..... move the downstream branch over here when you are done

You might use the same concept if you want to rewrite all the intermediate downstream revisions instead of having a single revisiom with all those changes.... it's just more work.

There is no royal road to solve this by magic. Basically these are the risks you took when you forked and diverged. If you don't like what they've done upstream, don't merge it, or merge it into something different from your working branch and deal with it piecemeal later. But one way or another, if you want to acquire their changes into your code, you just have to bite the bullet and take the time to resolve the conflicts.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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