简体   繁体   English

恢复已删除的提交

[英]Restore a deleted Commit

I was working on a project today, and i committed a month worth of changes, then I did a major change in the project which broke the whole project.我今天在做一个项目,我做了一个月的更改,然后我对项目进行了重大更改,这破坏了整个项目。

So I reset to the previous commit using所以我使用

git reset --hard <commit>

and then进而

git push origin HEAD --force

after than all my previous changes were gone because I choose the wrong commit to reset to (not sure).在我之前的所有更改都消失之后,因为我选择了错误的提交来重置(不确定)。 and whenever i write any git command now i get (not a git repository).每当我现在编写任何 git 命令时,我都会得到(不是 git 存储库)。

and I opened Bit Bucket and both commits are gone.我打开了 Bit Bucket,两个提交都消失了。 Is there ANYWAY to restore that commit PLEASE?有什么办法可以恢复那个提交吗?

The project is a groovy on Grails project.该项目是 Grails 项目上的一个常规项目。 I'm using intelliJ我正在使用智能

Your local repository keeps copies of commits for at least 30 days by default.默认情况下,您的本地存储库将提交的副本保留至少 30 天。 The repository over on Bitbucket probably does not. Bitbucket 上的存储库可能没有。

If you have not erased your local repository, look there for the commits.如果您尚未删除本地存储库,请在那里查找提交。 Use git reflog or git reflog <branchname> .使用git refloggit reflog <branchname> The reflog for HEAD holds the hash IDs that HEAD represented in the past. HEAD的 reflog 保存了HEAD过去表示的哈希 ID。 The reflog for the given branch name, such as master , holds the hash IDs that that branch name represented in the past.给定分支名称(例如master的引用日志包含该分支名称过去表示的哈希 ID。

If you were on branch xyzzy when you did the git reset --hard <commit> , xyzzy@{1} represents the hash ID that xyzzy held before this git reset --hard , so git reflog xyzzy will show you the commit you want.如果您在执行git reset --hard <commit>时在分支xyzzy上,则xyzzy@{1}表示xyzzygit reset --hard之前持有的哈希 ID,因此git reflog xyzzy将显示您想要的提交. You can now git reset --hard <commit> to that hash ID, pushing all the numbers up by one, ie, what was xyzzy@{1} is now xyzzy@{2} and the wrong commit hash ID you picked last time is now xyzzy@{1} .您现在可以git reset --hard <commit>哈希 ID,将所有数字加一,即xyzzy@{1}现在是xyzzy@{2}以及您上次选择的错误提交哈希 ID现在是xyzzy@{1} Meanwhile xyzzy (aka xyzzy@{0} ) is now the hash ID you just picked this time.同时xyzzy (又名xyzzy@{0} )现在是您这次刚刚选择的哈希 ID。

You can now git push origin HEAD or git push origin xyzzy to send this hash ID (and the commit(s), if they've lost it/them) to the Git at Bitbucket, and ask them to set their xyzzy to this hash ID.您现在可以git push origin HEADgit push origin xyzzy将这个哈希 ID(和提交,如果他们丢失了)发送到 Bitbucket 的 Git,并要求他们将他们的xyzzy设置为这个哈希ID。 You will only need --force if this operation loses some commit(s) on their end.如果此操作最终丢失了一些提交,您将只需要--force

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM