如何在 Bitbucket 中删除最新的 Git 提交?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/35979611/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-19 11:51:39  来源:igfitidea点击:

How to delete latest Git commit in Bitbucket?

gitgithubbitbucketgit-bash

提问by redshot

I am storing laravel files in bitbucket and I also have a local copy of the project. Every time i save my local copy, i push it to the remote repository in bitbucket so that they have the same update.

我将 Laravel 文件存储在 bitbucket 中,并且我还有该项目的本地副本。每次我保存本地副本时,我都会将它推送到 bitbucket 中的远程存储库,以便它们具有相同的更新。

Problem:I made a mistake in my local project and I want to delete the latest commit in Remote Repository in bitbucket.

问题:我在本地项目中犯了一个错误,我想删除 bitbucket 中远程存储库中的最新提交。

Does anyone know how to remove/delete the latest commit in bitbucket?

有谁知道如何删除/删除 bitbucket 中的最新提交?

Thanks

谢谢

采纳答案by Taj Ahmed

you can use git hard reset git reset documentationthen you just need to force push your repository

你可以使用 git hard reset git reset 文档然后你只需要强制推送你的存储库

回答by Menasheh

Start by undoing that last commit in your local repository:

首先撤消本地存储库中的最后一次提交:

If you want to uncommit but keep the changes in the file tree, use

如果要取消提交但保留文件树中的更改,请使用

git reset HEAD~1

If you want to completely get rid of the changes, run

如果您想完全摆脱更改,请运行

git reset --hard HEAD~1

Next, push your repository to bitbucket.

接下来,将您的存储库推送到 bitbucket。

(source and more detail)

(来源和更多细节)

回答by Alvaro Joao

git reset --soft HEAD^

git reset --soft HEAD^

First, remove the commit on your local repository. You can do this using git rebase -i. For example, if it's your last commit, you can do git rebase -i HEAD~2and delete the second line within the editor window that pops up.

首先,删除本地存储库上的提交。您可以使用git rebase -i. 例如,如果这是你最后一次提交,你可以git rebase -i HEAD~2在弹出的编辑器窗口中删除第二行。

Then, force push to your repby using git push origin +master.

然后,强制推到您的代表通过git push origin +master

See Git Magic Chapter 5: Lessons of History - And Then Somefor more information (i.e. if you want to remove older commits).

有关更多信息,请参阅Git 魔法第 5 章:历史教训 - 然后是一些(即,如果您想删除较旧的提交)。

please see alternative to git rebase -i

请参阅替代方案 git rebase -i

working tree is dirty, you have to do a git stashfirst, and then a git stash applyafter.

工作树很脏,你必须先做git stash,然后再做git stash apply

回答by CodeWizard

Check this post out:

看看这个帖子:

How to move HEAD back to a previous location? (Detached head)

如何将 HEAD 移回以前的位置?(分离的头)

It will describe methods for doing so.

它将描述这样做的方法。

But keep in mind that if your server does not allow force push you will not be able to to push old commit HEAD to the server,

但请记住,如果您的服务器不允许强制推送,您将无法将旧的提交 HEAD 推送到服务器,