Git Conflict Resolution Challenge: How to restore last saved code after conflicts

46 views Asked by At

I am encountering challenges in resolving conflicts in my React Native project using GitHub Desktop and VSCode. I worked in a branch fonts-and-colors that is forked from main. I was going to commit all new changes in my code to GitHub, but instead of commiting to fonts-and-colors branch I merged old commits in pull request into main from fonts-and-colors and created a new branch (home-screen) to commit the latest local changes. But encountered conflicts.

Right after the action above I saw the changes in my project code in VSCode.

I have tried using "Accept Current Change," "Accept Incoming Change," and "Accept Both Changes," to restore the code but none seem to incorporate my saved modifications. When selecting these options, the code incorporates some new changes but excludes some older modifications.

I want to get back my last saved version of the code.

Is there a step-by-step guide or specific approach I can follow to manually resolve these conflicts and ensure that my changes are preserved?

I appreciate any guidance or assistance. Thank you!

1

There are 1 answers

0
weshouman On

Following is how to have a clean version locally, and only once you are satisfied with the results push to the master again.

  1. Make a backup, copy the whole directory of the project to prevent further conflicts
  2. Pull from origin all the updates
  3. Identify the last commit that you find correct for the fonts-and-colors branch, using git log
  4. Create a branch out of it, for example git checkout -b fonts-and-colors-rescued <commit-hash>
  5. Move back to the main branch git checkout main
  6. Make a revert commit for the previous commits that were mistakenly pushed to main, for example, git revert OLDER_COMMIT^..NEWER_COMMIT
    Note: you could instead move the main to point to the previous commit and force push, which I do not recommend