如何真正删除VSTS/Azure-devops上的提交 [英] How to really delete a commit on VSTS / Azure-devops

查看:77
本文介绍了如何真正删除VSTS/Azure-devops上的提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用VS 2017,我们有一个云VSTS/Azure开发人员.

I'm working on VS 2017 and we have a cloud VSTS / Azure-devops.

我最近提交并推送了...,并意识到其中不应包含8个文件.之后,我再次承诺要清理干净并推到远程.

I recently committed and pushed... and realized that 8 files were not supposed to be in it. after that I committed again a clean one and pushed in to remote.

现在我可以在VSTS网站/portail中看到两个提交.

Now I can see both commit in VSTS website / portail.

问题是我需要创建一个PULL REQUEST,当我尝试创建一个Pull请求时,我发现自己位于Pull Request中的第一个提交文件中……这是我不想要的.

The thing is I need to create a PULL REQUEST, and when I try to create a pull request, I found myself with the first commit file inside the pull request... which I don't want.

因此,我只需要删除我所做的第一个提交,并为第二个干净的提交创建拉取请求.我该怎么走?原因是我搜索了却找不到明确的解释?

So I just need to delete the first commit I did, and create a pull request for the second clean commit. How do I go by? cause I searched and couldn't find a clear explanation on how to do?

推荐答案

您可以尝试执行以下步骤来删除整个提交:

You can try the following steps to remove an entire commit:

  1. Git将特定分支克隆到本地存储库:

  1. Git clone the specific branch to a local repository :

git clone --single-branch --branch分支名称https://xxx@dev.azure.com/xxx/0508-t/_git/0508-t

获取要删除的提交的 SHA :

导航到 https://dev.azure.com/{organization}/_git/{Project}/commits 页面->选择特定的提交->单击更多-> 复制完整SHA .(以下参考资料)

Navigate to https://dev.azure.com/{organization}/_git/{Project}/commits page -> Select the specific commit -> Click More -> Copy Full SHA . (Reference below sceenshot)

在git bash中运行此命令以删除本地存储库中的提交:

Run this command in git bash to remove the commit in local repository :

git rebase -p-到SHA ^ SHA

只需将" SHA "替换为您要删除的引用(从步骤2中获得的引用)即可.该命令中的"^"为文字.例如:

Just replace "SHA" with the reference you want to get rid of (the one you get from the step 2). The "^" in that command is literal. For example :

git rebase -p --onto 7e5661e7545013145dc7569edbe7c99f4b8d9671 ^ 7e5661e7545013145dc7569edbe7c99f4b8d9671

强制git push到原点:

Force git push to origin:

git push origin + test

在您要推送的分支名称之前注意 + 符号,这告诉git强制进行推送.值得一提的是,删除提交时应非常小心,因为一旦删除,它们就会永远消失.另外,如果您要从远程存储库中删除某些内容,请确保与团队协作以防止出现问题.

Notice the + sign before the name of the branch you are pushing, this tells git to force the push. It is worth to mention that you should be very careful when deleting commits because once you do it they are gone forever. Also, if you are deleting something from a remote repository make sure you coordinate with your team to prevent issues.

这篇关于如何真正删除VSTS/Azure-devops上的提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆