Project Fork From Branch

I need to fork my project, but a long time ago the ‘main’ branch of the project had some issues so we were forced to create a new ‘new_main’ branch and continue as a team to work from there.
The problem is that when we fork the project, it will only fork from ‘main’ but we need it to fork from ‘new_main’

I have tried to merge ‘new_main’ with ‘main’ but although it seems to run and I accept all changes from ‘new_main’ the resulting project is completely broken. (Notably there are missing nodes from the scene graph and probably missing assets too )

How can I resolve this?

I either want to fork from a different branch OR have my ‘main’ branch reset to exactly the same state as my ‘new_main’ branch.

Thanks

A branch is created from a checkpoint. Simply make a checkpoint on your “new_main” branch, select it and from drop down menu pick a new branch from it.

Ah, a fork. That is a feature currently. You can only fork a main branch. This might change in the future, but at the moment it is what it is.

Merging “new_main” to “main” is the way for you. Make 2 checkpoints on both branches and merge. Should work fine.

Well, I have tried that but it doesnt work at all. When I merge from new_main the resulting main branch is broken and is nothing like the branch I merged from (even though I accept all changes from new_main for each conflict)
Each branch (main and new_main) already has far more than two checkpoints.
Is there any possible workaround to get everything from a branch into a new project?
The graph itself just looks like spaghetti to me. I notice there is a copy data option but unclear exactly how this works. Is downloading all the data and re-uploading an option? (Getting desperate now))

Would ‘hard resetting’ my ‘main’ branch back to day 1 and THEN merging from ‘new_main’ be worth considering?

It sounds incredibly dangerous.

What are my options? Cheers

You could try to use Rest API to export the branch, and import it to a new project Projects - Archive project | PlayCanvas Developer Site

You have a very weird merge workflow where you have merged branches in a complicated manner. You have to treat it like git as that’s a what the VCS is based on.

Ideally, branches should be merged back into their source branch and not else where.

There are two main options.

Assuming ‘Branch B1’ is the branch you want to force merge into ‘main’, you have to reset main back to the checkpoint where you branched ‘Branch B1’ from.

This will delete all the checkpoints on main to that point but won’t delete branches and this is destructive. You cannot undo this.

Alternatively, the easier route is to use the API mentioned above. There’s a script that makes this bit easier and allows you to download an archive zip that you can import as a new project GitHub - playcanvas/playcanvas-rest-api-tools: A set of tools to use with the PlayCanvas REST API for common jobs such as downloading a build and archiving a project

1 Like

The graph is showing all the branches and checkpoints. The arrows show where merges and branches have happened across branches and commits to the same branch

If it looks complicated/spaghetti, then you should consider what in your teams workflow has cause it to be so. How are people branching and merging? How are changes tracked? Do you have clear developer guidelines on change and merge workflows?

1 Like

Yes, normally everything works smoothly but one time there was a ton of work done on several branches and when they were merged back there were many issues. The only way to remedy the issue was to create a new branch and continue from there. I have no idea how it happened as normally we don’t have problems.
I will try using the script first. If I run into problem I guess I will have to hard reset my main branch back to much earlier. Can you confirm that this wont delete branches when/if I do it?

Usually when this happens, it’s because of how merges to the branch have been resolved. As when future merges happen, it only merges changes since the last common ancestor in the graph.

When I was still supporting, debugging this involved looking at all the merge checkpoints on main for the offending change(s)

Arguably the correct workflow should have been to fix the main branch over creating a new ‘main’

You need to ask the PlayCanvas team for confirmation. When I was still on the team a few years back, doing a hard reset didn’t delete other branches.

Thanks Mike. Yeah, having looked at the setup and scripts for the rest-api-tools it looks super complicated and I have no idea what I am doing :frowning:
Hard Resetting might be my only option. Hopefully the Playcanvas team might chime in.
Is there a (easy) way to completely back up a project first?

I’m not Mike :grimacing:

Unfortunately not. The closest you get is the script to get an archive of each branch individually

Sorry, I meant Steven :slight_smile: I ‘think’ I even used to work with you at EA back in the day.

1 Like

UK Chertsey/Guildford office?

I worked at both Chertsey and Guildford. Was a designer on Goblet or Fire , then after a short stint on Order of The Pheonix moved across to ‘Podo’. That finished me :smile:

1 Like

There’s a less destructive method that I forgot about

Assuming B1 is the branch you want to force merge to main

Make a checkpoint in B1 (let’s call this B1 CP)

Make a checkpoint in main

Merge main to B1 to create a new common ancestor. Doesn’t matter what state the merge is in

Restore checkpoint B1 CP to restore the state of branch B1 before the merge as new changes

Make a checkpoint on branch B1

Merge B1 to main. This should be a clean merge.

I have no idea what kind of magic that is, but it worked!!

Thank You so much!!

To explain this a bit, it creates a common ancestor point in the VC graph. So when you merge main to B1 or visa versa, it applies the changes made since the common ancestor checkpoint you’ve just made

Restoring a checkpoint changes the state of the branch to be the same as the checkpoint you are restoring but as new changes since the previous checkpoint made in the branch

So when you merge B1 to main, it applies all changes in B1 since the common ancestor checkpoint to main

2 Likes

This is great. Thanks again!