0

6 commits were made to the repository over night and unfortunately the changes are bad. I want to remove the last 6 commits to the repository and make a specific commit the new "latest". There are multiple devs pushing/pulling to this repository so I'm not sure how to do this without getting everyone out of sync. My git knowledge is quite limited.

Through the git UI in Visual Studio how would this be done?

Legion
  • 3,922
  • 8
  • 51
  • 95
  • Your question is more about VS than about Git, but underneath VS, Git provides two options: you can either *add a new commit* that rolls back the work, or, you can literally roll back the work. The `git reset --hard` technique uses "roll back the work". Be aware that whenever anyone does this, *everyone else* needs to do work to synchronize. For this reason it's usually considered easier/better to *add a new commit* instead. – torek Nov 30 '22 at 01:40
  • A quick search of StackOverflow will find many, many questions and answers that cover both of these options quite thoroughly. Translating those to VS is a VS question. I don't use VS and can't provide further advice. – torek Nov 30 '22 at 01:41

1 Answers1

1

You should be able to right click on the commit you want to be the "latest" and reset your local branch to it:

right click reset menu

By doing this, you will lose any commits that are ahead of the commit you are reverting to on the branch once you push, however it sounds like this should be fine for your scenario since these 6 commits in question are as you worded it, "bad".

You can read up on the mixed and hard settings here, but I think it sounds like you probably want --hard unless you have changes that you need to also commit as part of this "latest" commit.

After you reset, you can push to the remote branch, which you may need to do a force push. Afterwards, the branch should be reverted back to the commit you selected, and anyone that pulls it will be at the same commit.

Timothy G.
  • 6,335
  • 7
  • 30
  • 46