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 comm
You can just do git merge <commit-number>
or git cherry-pick <commit> <commit> ...
As suggested by Ryan Stewart you may also create a branch from the current HEAD:
git branch brand-name
Or just a tag:
git tag tag-name
This is what I did:
Basically, think of the detached HEAD
as a new branch, without name. You can commit into this branch just like any other branch. Once you are done committing, you want to push it to the remote.
So the first thing you need to do is give this detached HEAD
a name. You can easily do it like, while being on this detached HEAD
:
git checkout -b some-new-branch
Now you can push it to remote like any other branch.
In my case, I also wanted to fast-forward this branch to master along with the commits I made in the detached HEAD
(now some-new-branch
). All I did was
git checkout master
git pull # To make sure my local copy of master is up to date
git checkout some-new-branch
git merge master // This added current state of master to my changes
Of course, I merged it later to master
.
That's about it.
You could do something like this.
# Create temporary branch for your detached head
git branch tmp
# Go to master
git checkout master
# Merge in commits from previously detached head
git merge tmp
# Delete temporary branch
git branch -d tmp
Even simpler would be
git checkout master
git merge HEAD@{1}
but this has the slight danger that if you do make a mistake it can be a little harder to recover the commits made on the detached head.
In case of detached HEAD, commits work like normal, except no named branch gets updated. 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.
git branch temp
git checkout master
git merge temp
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
Alternatively, you could cherry-pick the commit-id onto your branch.
<commit-id> made in detached head state
git checkout master
git cherry-pick <commit-id>
No temporary branches, no merging.