简体   繁体   English

如何从 Visual Studio 2022 中的 Git 存储库中删除最后 6 次提交?

[英]How can I remove the last 6 commits from a Git repository in Visual Studio 2022?

6 commits were made to the repository over night and unfortunately the changes are bad.一夜之间对存储库进行了 6 次提交,不幸的是这些更改很糟糕。 I want to remove the last 6 commits to the repository and make a specific commit the new "latest".我想删除对存储库的最后 6 次提交,并使特定提交成为新的“最新”。 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.我的 git 知识相当有限。

Through the git UI in Visual Studio how would this be done?通过 Visual Studio 中的 git UI 将如何完成?

You should be able to right click on the commit you want to be the "latest" and reset your local branch to it:您应该能够右键单击您想要成为“最新”的提交并将您的本地分支重置为它:

右键重置菜单

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".通过这样做,一旦你 push ,你将失去你在分支上恢复到的提交之前的任何提交,但是听起来这对你的场景应该没问题,因为这 6 个提交有问题,正如你所说的那样,“坏的”。

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.您可以在此处阅读有关mixed设置和hard设置的信息,但我认为这听起来像是您可能想要--hard除非您还需要将更改作为此“最新”提交的一部分提交。

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.之后,该分支应恢复为您选择的提交,并且拉取它的任何人都将处于同一提交。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从git存储库中完全删除/销毁提交? - How can I completely remove/destroy commits from a git repository? Visual Studio 2022:如何禁用 Git 存储库的新功能(3 个窗口)? - Visual Studio 2022: How to disable the New feature(3 windows) of Git repository? 如何在 Visual Studio 代码中忽略整个 git 存储库? - How can I ignore whole git repository in visual studio code? 如何从 git 中删除分离的提交? - How can i remove detached commits from git? 从Visual Studio解决方案中删除项目后,如何从Git存储库中删除Visual Studio 2015项目? - How do I remove a Visual Studio 2015 project from my Git repository after I remove that project from my Visual Studio solution? 如何在Visual Studio 2015中创建Git裸存储库? - How can I create a Git bare repository from within Visual Studio 2015? 如何从 git 存储库中删除所有无更改提交? - How to remove all no-change commits from git repository? 我如何在 visual studio 2022 中不快进进行 git 合并? - how do I git merge with no fast forward in visual studio 2022? 如何删除git中的最后两个提交并在工作目录中将我的提交1作为更改? - How can I remove last two commits in git and get my commit 1 as changes in working directory? 将现有的 Visual Studio 2022 解决方案添加到新的 Azure Git 存储库 - Adding an existing Visual Studio 2022 Solution to a new Azure Git Repository
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM