how to rebase changes in the master to detached HEAD safely












2















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?










share|improve this question





























    2















    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?










    share|improve this question



























      2












      2








      2








      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?










      share|improve this question
















      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?







      git branch git-detached-head






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 21 '18 at 9:15









      Mureinik

      185k22137203




      185k22137203










      asked Nov 21 '18 at 4:04









      user2372074user2372074

      2613415




      2613415
























          1 Answer
          1






          active

          oldest

          votes


















          2














          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:



          $ git checkout a32b42b123 -b mybranch 
          # make some changes, commit
          $ git fetch origin
          $ git rebase origin/master





          share|improve this answer
























          • but doing this rebase will lose the previous change I made on a32b42b123, right?

            – user2372074
            Nov 21 '18 at 17:29











          • @user2372074 Commits are read-only. You cannot change a32b42b123 once its created - you can make changes in the branch, and rebasing the branch will retain them (assuming no merge conflicts, of course!)

            – Mureinik
            Nov 21 '18 at 17:33











          • Thanks for the reply, after rebasing, all the changes are gone.

            – user2372074
            Nov 22 '18 at 2:34











          • @user2372074 please share exactly what you've done

            – Mureinik
            Nov 22 '18 at 5:42











          • Thanks, I did git checkout master && git pull origin master git checkout a32b42b123 && git rebase master' @user2372074

            – user2372074
            Nov 28 '18 at 18:47













          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405107%2fhow-to-rebase-changes-in-the-master-to-detached-head-safely%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          2














          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:



          $ git checkout a32b42b123 -b mybranch 
          # make some changes, commit
          $ git fetch origin
          $ git rebase origin/master





          share|improve this answer
























          • but doing this rebase will lose the previous change I made on a32b42b123, right?

            – user2372074
            Nov 21 '18 at 17:29











          • @user2372074 Commits are read-only. You cannot change a32b42b123 once its created - you can make changes in the branch, and rebasing the branch will retain them (assuming no merge conflicts, of course!)

            – Mureinik
            Nov 21 '18 at 17:33











          • Thanks for the reply, after rebasing, all the changes are gone.

            – user2372074
            Nov 22 '18 at 2:34











          • @user2372074 please share exactly what you've done

            – Mureinik
            Nov 22 '18 at 5:42











          • Thanks, I did git checkout master && git pull origin master git checkout a32b42b123 && git rebase master' @user2372074

            – user2372074
            Nov 28 '18 at 18:47


















          2














          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:



          $ git checkout a32b42b123 -b mybranch 
          # make some changes, commit
          $ git fetch origin
          $ git rebase origin/master





          share|improve this answer
























          • but doing this rebase will lose the previous change I made on a32b42b123, right?

            – user2372074
            Nov 21 '18 at 17:29











          • @user2372074 Commits are read-only. You cannot change a32b42b123 once its created - you can make changes in the branch, and rebasing the branch will retain them (assuming no merge conflicts, of course!)

            – Mureinik
            Nov 21 '18 at 17:33











          • Thanks for the reply, after rebasing, all the changes are gone.

            – user2372074
            Nov 22 '18 at 2:34











          • @user2372074 please share exactly what you've done

            – Mureinik
            Nov 22 '18 at 5:42











          • Thanks, I did git checkout master && git pull origin master git checkout a32b42b123 && git rebase master' @user2372074

            – user2372074
            Nov 28 '18 at 18:47
















          2












          2








          2







          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:



          $ git checkout a32b42b123 -b mybranch 
          # make some changes, commit
          $ git fetch origin
          $ git rebase origin/master





          share|improve this answer













          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:



          $ git checkout a32b42b123 -b mybranch 
          # make some changes, commit
          $ git fetch origin
          $ git rebase origin/master






          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 21 '18 at 4:31









          MureinikMureinik

          185k22137203




          185k22137203













          • but doing this rebase will lose the previous change I made on a32b42b123, right?

            – user2372074
            Nov 21 '18 at 17:29











          • @user2372074 Commits are read-only. You cannot change a32b42b123 once its created - you can make changes in the branch, and rebasing the branch will retain them (assuming no merge conflicts, of course!)

            – Mureinik
            Nov 21 '18 at 17:33











          • Thanks for the reply, after rebasing, all the changes are gone.

            – user2372074
            Nov 22 '18 at 2:34











          • @user2372074 please share exactly what you've done

            – Mureinik
            Nov 22 '18 at 5:42











          • Thanks, I did git checkout master && git pull origin master git checkout a32b42b123 && git rebase master' @user2372074

            – user2372074
            Nov 28 '18 at 18:47





















          • but doing this rebase will lose the previous change I made on a32b42b123, right?

            – user2372074
            Nov 21 '18 at 17:29











          • @user2372074 Commits are read-only. You cannot change a32b42b123 once its created - you can make changes in the branch, and rebasing the branch will retain them (assuming no merge conflicts, of course!)

            – Mureinik
            Nov 21 '18 at 17:33











          • Thanks for the reply, after rebasing, all the changes are gone.

            – user2372074
            Nov 22 '18 at 2:34











          • @user2372074 please share exactly what you've done

            – Mureinik
            Nov 22 '18 at 5:42











          • Thanks, I did git checkout master && git pull origin master git checkout a32b42b123 && git rebase master' @user2372074

            – user2372074
            Nov 28 '18 at 18:47



















          but doing this rebase will lose the previous change I made on a32b42b123, right?

          – user2372074
          Nov 21 '18 at 17:29





          but doing this rebase will lose the previous change I made on a32b42b123, right?

          – user2372074
          Nov 21 '18 at 17:29













          @user2372074 Commits are read-only. You cannot change a32b42b123 once its created - you can make changes in the branch, and rebasing the branch will retain them (assuming no merge conflicts, of course!)

          – Mureinik
          Nov 21 '18 at 17:33





          @user2372074 Commits are read-only. You cannot change a32b42b123 once its created - you can make changes in the branch, and rebasing the branch will retain them (assuming no merge conflicts, of course!)

          – Mureinik
          Nov 21 '18 at 17:33













          Thanks for the reply, after rebasing, all the changes are gone.

          – user2372074
          Nov 22 '18 at 2:34





          Thanks for the reply, after rebasing, all the changes are gone.

          – user2372074
          Nov 22 '18 at 2:34













          @user2372074 please share exactly what you've done

          – Mureinik
          Nov 22 '18 at 5:42





          @user2372074 please share exactly what you've done

          – Mureinik
          Nov 22 '18 at 5:42













          Thanks, I did git checkout master && git pull origin master git checkout a32b42b123 && git rebase master' @user2372074

          – user2372074
          Nov 28 '18 at 18:47







          Thanks, I did git checkout master && git pull origin master git checkout a32b42b123 && git rebase master' @user2372074

          – user2372074
          Nov 28 '18 at 18:47






















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53405107%2fhow-to-rebase-changes-in-the-master-to-detached-head-safely%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          How to pass form data using jquery Ajax to insert data in database?

          National Museum of Racing and Hall of Fame

          Guess what letter conforming each word