Jan
Jan

Reputation: 1318

Branch merged, commit lost

I currently have an issue regarding Git. My repository is hosted on bitbucket.org. I worked on a branch named new-documentation, I worked on development before, so it was equal to development. In the meantime, someone else pushed a commit to development. Nothing difficult, I thought. Later, I created a pull request on bitbucket. Of course, it had some merging issues because of conflicts. So I went into my console and manually merged the changes and deleted the new-documentation branch. However, when I pushed the changed development branch, not everything was merged into it. Can I somehow recover the branch or its contents? When I look at bitbucket, I can still see the open merge request with all its changes, when I click on "View File", I can even see my changes to it. But when I try to cherry-pick the revision, Git says it's invalid.

Is there any way to solve the issue?

Upvotes: 1

Views: 96

Answers (2)

Mudassir Razvi
Mudassir Razvi

Reputation: 1833

Run git reflog and find the hash of branch new-documentation and create a branch there.
1. git relog [And find the hash of the branch new-documentation]
2. git checkout -b [branch-name] [sha-you-found]

This will create a branch to where your new-documentation branch was. Now rebase it over development and merge development to new-documnetation and push.

Upvotes: 1

CodeWizard
CodeWizard

Reputation: 141946

If you did not execute git gc you still have it all on your machine (locally). type git reflog and checkout the desired commit with your code, then create branch from this point and do what ever you need to do.

Upvotes: 0

Related Questions