I did not realize I've been working on a detached HEAD (a32b42b123) branch until now. This branch is falling behind master a lot. I did the following operations,
git checkout master && git pull origin master
git checkout a32b42b123 && git rebase master
to sync up this branch with master and noticed most of the changes I made in this branch are gone. Now I understand what a detached HEAD is. But how could I perform the git rebase master
safety here without wiping out the change I made?
how to rebase changes in the master to detached HEAD safely
236 Views Asked by user2372074 At
1
Commits in Git are immutable. If you started off at a32b42b123 and made changes, the tip of your branch would no longer be a32b42b123, but a different commit. When you checkout back to that commit, as you've seen, you lose the changes you've made on top of it.
You could, of course, use detached head, but that's just making live difficult for no (good) reason, especially when branches are so cheap. Just create a named branch from that commit and make your changes there: