如何在Github和Bitbucket上从git删除提交 [英] How to delete commits from git on Github and Bitbucket

查看:365
本文介绍了如何在Github和Bitbucket上从git删除提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不小心从.gitignore文件中的Django项目的.idea目录中推送了文件.我正在尝试从我的bitbucket存储库中完全删除提交,因为我还有其他人在与该项目一起工作,他不能在不影响自己的.idea文件的情况下提取我的更改.我还看到了其他SO问题,他们说要使用git revert,但是我记得还有另一个命令在其中推送了您所做的最后一次良好提交,此后的所有内容都从master分支中删除了.例如

I accidentally pushed up files from my .idea directory in my Django project which I had in my .gitignore file. I am trying to completely delete the commit from my bitbucket repository since there is someone else Im working with on the project and he can't pull my changes without affecting his own .idea files. I have seen other SO questions where they say to use git revert, however I remember there was another command where you pushed the last good commit you made, and everything after that was deleted from the master branch. For example

提交历史记录:

94ca48e

55fab05

3813803

我要删除94ca48e和55fab05.我曾经找到一个命令,可以将3813803作为最新的提交,并且该提交之后远程存储库中的所有内容都将被删除,但是我在任何地方都找不到它.

I want to delete 94ca48e, and 55fab05. There was a command I found once where you could make 3813803 the most current commit, and everything in the remote repository after that commit would be deleted, but I can't find it anywhere.

推荐答案

使用git reset --hard 3813803.此不能撤消,可以在本地和远程运行.

Use git reset --hard 3813803. This can not be undone and works locally as well as remote.

对于使用git push --force origin master

在Atlassian的此处中查看git文档.

Have a look at the git docu by Atlassian here.

我也从那里引用:

鉴于还原旨在安全地撤消公共提交,而git reset旨在撤消本地更改.由于它们的目标截然不同,因此这两个命令的实现方式有所不同:重置会完全删除变更集,而还原会保留原始变更集,并使用新的提交来应用撤消.

Whereas reverting is designed to safely undo a public commit, git reset is designed to undo local changes. Because of their distinct goals, the two commands are implemented differently: resetting completely removes a changeset, whereas reverting maintains the original changeset and uses a new commit to apply the undo.

但是,

git reset是这里要使用的那个,因为您要求完全删除.

git reset is the one to be used here, though, because you are asking for complete deletion.

这篇关于如何在Github和Bitbucket上从git删除提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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