Fixing accidentally merging to master (instead of develop) branch
Recently a friend ran into an issue where the branch they thought they were working on was the development branch when in fact it was the master branch. She was asking how to get the changes she had just made, back into the development branch since they were on the master. Since these branches had been at the same commit prior to the work she had done the solution was simple, checkout the development branch and run git merge master and this solved her issue.
One of hurdles of people coming from a different version control system to git is not knowing that the master branch is only the master branch by convention. Having a branch called master doesn't make it any more powerful or give any more privileges than any other branch. This is a beautiful part about Git, the only limitations on these branches are those that you put on them (or that are put on them by your dev standards).
By convention (not by law) the master branch is meant to be production ready at all times. When she made changes to the master branch and committed them, this branch was no longer production ready since the changes hadn't been fully tested yet. By checking out the development branch and merging the changes back there it resolved her issue, but one issue was left (that she wasn't concerned about because it wasn't code in production yet) and that was rewinding the master branch to the production ready state that it had been in prior to her changes.
In order to do that she could do a git revert. To do this she would need to do a git log to find the commit she wants to revert to, get the sha-1 of that commit and run the following: git revert --hard <sha-1> where <sha-1> is the hash of the commit she would like to revert to.
Now this would put her back into the state of a production ready master branch and a development branch.
Post new comment