Reputation: 31
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).
and I opened Bit Bucket and both commits are gone. Is there ANYWAY to restore that commit PLEASE?
The project is a groovy on Grails project. I'm using intelliJ
Upvotes: 1
Views: 1473
Reputation: 487755
Your local repository keeps copies of commits for at least 30 days by default. The repository over on Bitbucket probably does not.
If you have not erased your local repository, look there for the commits. Use git reflog
or git reflog <branchname>
. The reflog for HEAD
holds the hash IDs that HEAD
represented in the past. The reflog for the given branch name, such as master
, holds the hash IDs that that branch name represented in the past.
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. You can now git reset --hard <commit>
to that hash ID, pushing all the numbers up by one, i.e., what was xyzzy@{1}
is now xyzzy@{2}
and the wrong commit hash ID you picked last time is now xyzzy@{1}
. Meanwhile xyzzy
(aka xyzzy@{0}
) is now the hash ID you just picked this time.
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. You will only need --force
if this operation loses some commit(s) on their end.
Upvotes: 1