Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can I recover a GitLab merge request for a deleted branch?

Tags:

gitlab

While doing some branch maintenance today, I lost a MR and the associated discussion. Not a tragedy but I'd like to get it back if possible. I found an open GitLab enhancement request to undo branch delete but that doesn't quite seem to be what I want. Here's what happened:

Branch A was pushed to our local installation of GitLab, an MR created, and some discussion ensued. We realized that A was a good start but we needed some significant refactoring. We hoped to keep the branch name for the work we'd ultimately merge/ship so we:

  • Created A-prime on the local system and pushed it to GitLab
  • Deleted A, hoping that the MR would be associated with the commits, not the branch. But when we deleted A, the MR was no longer accessible.
  • Recreated A at the same commit as it had been and pushed it to GitLab hoping the MR was hanging out and would get reassociated.

Clearly our mental model of GitLab is wrong. It seems that a post-commit hook or something deletes MRs as a branch is deleted. My question now is: can I get the deleted MR and its discussion back?

like image 388
Chris Nelson Avatar asked Nov 20 '18 22:11

Chris Nelson


People also ask

Can a deleted branch be recovered?

There is no retention policy on deleted branches. A deleted Git branch can be restored at any time, regardless of when it was deleted.

How do I restore a merged branch?

You can undo a Git merge using the git reset –merge command. This command changes all files that are different between your current repository and a particular commit. There is no “git undo merge” command but the git reset command works well to undo a merge.

How do I recover a deleted pull request?

Restoring a deleted branchUnder your repository name, click Pull requests. Click Closed to see a list of closed pull requests. In the list of pull requests, click the pull request that's associated with the branch that you want to restore. Near the bottom of the pull request, click Restore branch.

What happens when a branch is deleted?

What Happens If I Delete a Git Branch? When you delete a branch in Git, you don't delete the commits themselves. That's right: The commits are still there, and you might be able to recover them.


Video Answer


1 Answers

I apologize for wasting the communities time. I'm a GitLab newbie and was stumbling around. I didn't stumble far enough. Today we discovered that you can get to the original MR if you have the URL. When you get there, it's Closed, as you'd expect, I suppose. If you go back to the project level and navigate to MRs, then pick the Closed tab, it's there. It likely was there all along but in our panic and newbiness, we didn't find it.

like image 51
Chris Nelson Avatar answered Sep 23 '22 18:09

Chris Nelson