nus-cs2103-AY2324S2 / forum

17 stars 0 forks source link

Github "Sync fork" button interleaves my commits and my teammates' #649

Open yyccbb opened 4 months ago

yyccbb commented 4 months ago

My teammates and I are working on separate branches and one of them merged a PR into the team codebase. I clicked the "Sync fork" button after pushing some commits to the branch I am working on. This caused my commit history to be messed up completely, with my teammates' commits and mine interleaved. My code has got numerous compilation errors because of this.

Is there any way that I can undo the sync fork action?

E0735389 commented 4 months ago

First, as you know how git works, the commit history is not linear. Rather, it's a tree-like structure.

git log or similar tools, however, list the commits chronologically, so it's normal that the commits appear interleaved.

Usually, git merge is intelligent enough to correctly apply the patches. The rest you have to resolve manually. That's just the normal merge conflict resolution process.

You can certainly undo the sync fork feature if it gets too difficult. You can do the following:

But because it's desirable for you to apply the new change anyway, assume the current tree structure is:

  --- B
 /
A
 \
  --- C

your branch is C, your friend's branch is B. Then do git diff A C to see all the developments you made, git reset --hard B to move to the merged upstream/master, then manually reapply the changes.

damithc commented 4 months ago

Good inputs from @E0735389

@yyccbb if you still can't figure out a solution, can you post the link to the branch in concern?

Also note that we recommend using the standard Git way of syncing repos (covered in course materials) instead of using GitHub-specific features such as 'sync fork'.