Using git I made something like this
git clone git checkout {a rev number tree rev before} (here I started to be in a detached head state) //hacking git commit //hacking git commit (some commit where made on origin/master) git pull (which does complete because there was some error due to the fact that I'm no more on master)
Because it said to me that I can still commit when in a detached head state, I did so. But now I want to like merge my detached head branch and my local master branch, and then push my bunch of changes to origin/master.
So my question is how could I merge the master branch with my actual state (detached head)
If you want to discard the changes in the detached HEAD state, you only need to check out to the existing or previous branch. The commits on the detached HEAD state will not affect your existing branch, and Git will archive them.
If you want to keep changes made with a detached HEAD, just create a new branch and switch to it. You can create it right after arriving at a detached HEAD or after creating one or more commits. The result is the same. The only restriction is that you should do it before returning to your normal branch.
Detached head usually means that the branch you checkout to does not has the latest commit. So, basically you need to adjust the HEAD of your current branch to the latest commit. There are usually 2 ways to do it. You can create a new branch, push your code to that branch (this will pull your detached code too).
To get master branch updated with your committed changes, make a temporary branch where you are (this way the temporary branch will have all the committed changes you have made in the detached HEAD) , then switch to the master branch and merge the temporary branch with the master.
Create a branch where you are, then switch to master and merge it:
git branch my-temporary-work git checkout master git merge my-temporary-work
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With