From ae394971ed1b92b51afec35a752a27fd9bfd0de3 Mon Sep 17 00:00:00 2001 From: GregF Date: Wed, 28 Feb 2024 21:00:22 +0000 Subject: [PATCH] Add undoing an accidental merge --- Git-Basics.md | 35 ++++++++++++++++++++++++++++++++++- 1 file changed, 34 insertions(+), 1 deletion(-) diff --git a/Git-Basics.md b/Git-Basics.md index f13a5e0..cb4d53c 100644 --- a/Git-Basics.md +++ b/Git-Basics.md @@ -92,4 +92,37 @@ $ git checkout cider $ git rebase master $ git push origin cider ``` -And now your `cider` branch is updated onto the changes present in the updated master branch. \ No newline at end of file +And now your `cider` branch is updated onto the changes present in the updated master branch. + +## Best Practices: Undoing an accidental merge +At some point you probably will accidentally merge the main repo into your branch. +You will need to undo this; we cannot accept MRs that have a merge as a commit. +The sooner you fix it the better. + +Let's say you have accidentally merged changes from the main repo into a branch caller `cider` on your fork. +Here's how you can undo it: + +0) If you are worried you may lose some work copy the files somewhere else. +In theory you should not lose anything but if you do not feel confident with git copy your changes elsewhere. + +1) Roll your branch back to before you merged (ideally just one commit back): +``` +git reset --hard HEAD~1 +``` + +or + +``` +git reset --hard {commit hash} +``` + +2) Force push this rollback to *your* repo/branch (`cider` in this example) + +``` +git push --force origin cider +``` + +3) Follow [Best Practices: Updating Your Fork](Git-Basics.md?ref_type=heads#best-practices-updating-your-fork). + +4) If you've lost something you did not backup you can use ```git checkout {hash}``` to try and find the pieces. +