Home > Software engineering >  Reverting a few of the commits to the repository, while saving the commits that are being reverted i
Reverting a few of the commits to the repository, while saving the commits that are being reverted i

Time:10-29

We are migrating our code to a higher version of the underlying framework (.NET 6). This has resulted in a few commits to the repository. It was recently decided that we are not yet ready for the upgrade. We have now been asked to possibly move all the commits to a separate branch and revert those from the main one for now. The commits moved to the separate branch would later be applied to the main when we are ready for the .NET 6 upgrade. What would be the best way to achieve this using Visual Studio (or any other tool)?

The commit tree looks like this: enter image description here

I need to move all the commits in pink (B, D, E, F, G, H, I and J) to a separate branch, and keep just the other ones (A and C).

CodePudding user response:

A possible 3 step process:

# To be executed from your branch pointing at J (that you didn't name here)

# 1) tag J for later
git tag backup-j -m "backup point to resume work from later"

# 2) restore your current branch to A
git reset --hard A

# 3) get a copy of C
git cherry-pick C

When, at a later point you'll want to resume working on that J backup, just do

git checkout -b your_new_branch backup-j

so that the new branch is created from the tag we've set at 1).

  • Related