Bitbucket git 重置
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/19249572/
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
Bitbucket git reset
提问by malcoauri
I've done this git commands:
我已经完成了这个 git 命令:
git reset --hard hash
git push -f
All was good locally, I don't see any commits after 'hash' commit. All was good after pushing too, there were no errors, but on Bitbucket main panel of my repository (Overview) last commits still are. And I don't understand it, have I reset remote repository or not?
在本地一切都很好,在“哈希”提交后我没有看到任何提交。推送后一切都很好,没有错误,但在我的存储库(概述)的 Bitbucket 主面板上,最后一次提交仍然存在。我不明白,我是否重置了远程存储库?
采纳答案by Schleis
The problem is that your SHA's have not changed so Git doesn't really update the remote on BitBucket. The history after where you reset still exists, you would be able to do git pulland your local repo would get all the later commits.
问题是你的 SHA 没有改变,所以 Git 并没有真正更新 BitBucket 上的遥控器。重置后的历史记录仍然存在,您可以这样做,git pull并且您的本地存储库将获得所有后来的提交。
After doing the git reset --hard HASH, do a git reset HEAD~(note: this is a soft reset) Then recommit the changes. This will generate a new SHA for the commit and when you force push your changes, the tree on BitBucket should be updated as you expect.
做完之后git reset --hard HASH,做一个git reset HEAD~(注意:这是一个软重置)然后重新提交更改。这将为提交生成一个新的 SHA,当您强制推送更改时,BitBucket 上的树应该按您的预期更新。
WARNINGThis is changing history and if there are others that have pulled from the repo, it will cause trouble. This should not be a normal workflow for undoing changes on a remote branch, you should use git revert.
警告这是正在改变的历史,如果有其他人从 repo 中撤出,它会造成麻烦。这不应该是撤消远程分支上的更改的正常工作流程,您应该使用git revert.
回答by Hymanyalcine
git resetdoesn't delete commits; if that's your intent. It resets the current working tree (staged changes to be committed) on your local machine.
git reset不删除提交;如果那是你的意图。它会重置本地计算机上的当前工作树(要提交的暂存更改)。

