AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |
Back to Blog
Undo merge git9/10/2023 That’s where the -m flag comes in - passing in a 1 points it to the branch that you had checked out when you began the merge (passing in a 2 would point to the branch that was merged in, which isn’t useful in our case). However, because a merge commit by nature has two parent commits (one from each branch you are merging together), you need to specify which parent is the “mainline” - the base branch you merged into. Normally, you can feed git revert the hash of the commit you want to undo, and Git will then look at that commit’s pointer to its parent commit to determine which changes to revert. This means that both the original commit and the new inverse commit will both be stored in history, preserving all of the data about what happened but leaving your branch in the state it was before you made the first commit.ĭue to the way merges work, you have to do a little extra work, though. Git revert generates a series of changes that, when applied, produce the exact inverse of whatever commit you give to it, then creates a new commit with those changes. We can use this information to run the git revert command to restore your branch to the state that it was in previously. How does reverting a merge work?Īs it does with regular commits, Git creates merge commits with a commit hash representing the point in history where the other branch was merged in. happened on GitHub) you can push this commit like any other and you’ll be set to go. Once you have that, you can pass it to the git revert command to undo the merge:Īnd Bob’s your uncle! The git revert command will have generated a commit that restores your branch’s state to where it was before the faulty merge. In this case, `52bc98d` is our merge’s hash. The commit hash is the seven character string in the beginning of each line.
0 Comments
Read More
Leave a Reply. |