Home > database >  How can I remove the last 6 commits from a Git repository in Visual Studio 2022?
How can I remove the last 6 commits from a Git repository in Visual Studio 2022?

Time:12-01

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?

CodePudding user response:

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.

  • Related