Add undoing an accidental merge

This commit is contained in:
GregF 2024-02-28 21:00:22 +00:00
parent da3a0d73f2
commit ae394971ed

View file

@ -93,3 +93,36 @@ $ git rebase master
$ git push origin cider
```
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.