Previously my code was infected by a horrifying bug wreaking havoc. After a long fight I decided to just $git checkout to a pre-bug commit.
And now $git branch returns a list with the branch “(no branch)” marked. How do I merge (is that the right one?) this into the master branch?
Bonus question: what does even “(no branch)” mean? Can it really be no branch?
Yes, it can really be “no branch”. You’re running in a state called “detached head”. If you’re not careful, you are going to lose your changes. In a detached head state, git isn’t updating any reference. As a result, if you checkout some other branch, you may lose track of where you were at… and the changes that go with it.
First, give your branch a name:
Next, if you want to make your master branch look like the new branch, you have a few choices… some that can lose the history of master, and some that will preserve it. I’ll assume you want the latter.
The easiest thing to do is while on your new branch, run:
That will bring in master, but won’t apply any of it’s changes due to the
-s oursoption (this selects theoursmerge strategy). Then checkout master, and run:At that point, master should look like new-branch-name.