Reputation: 10603
We had a commit that fixed an issue on our codebase that was merged via a pull request. The commit is now nowhere to be found. I have no idea how it was deleted as it was long time ago. The good thing is that I can see the pull request, the commit hash and change diff on Stash. If all this information still exists on stash how do I recover the commit?
Upvotes: 1
Views: 330
Reputation: 37944
If you know the commit hash, you can check if the commit exists in your local repository by simply calling git show
:
git show <commit-id>
If the commit is still there, you can create a new branch from that using git branch
git branch save-my-old-commit <commit-id>
If the commit it not present in your local repository (which is possible, when not reachable from any ref), you can try to fetch it directly from the remote repository and then check out a new branch:
git fetch origin <commit-id>
git branch save-my-old-commit FETCH_HEAD
If the original commit originated from a pull request, you can also try pulling from the forked repository (I have no experience with Stash, so I'm assuming it works similar to GitHub or Gitlab).
After you have restored the commit to a local branch, you can proceed as you see fit, for example by cherry-picking the commit on top of your current branch.
Upvotes: 3
Reputation: 141946
You have several options (im listing only few of them, there are more options):
git bisect
to find out when (commit) it was "gone"git reflog
on the develop machine to view exactly what was done and when (is the repo was not cloned after that point)My recommendation is to use git bisect
to find when it was gone.
Upvotes: 0