how to rebase changes in the master to detached HEAD safely
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
add a comment |
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
add a comment |
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
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
git branch git-detached-head
edited Nov 21 '18 at 9:15
Mureinik
185k22137203
185k22137203
asked Nov 21 '18 at 4:04
user2372074user2372074
2613415
2613415
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
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
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 changea32b42b123once 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
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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
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 changea32b42b123once 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
add a comment |
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
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 changea32b42b123once 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
add a comment |
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
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
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 changea32b42b123once 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
add a comment |
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 changea32b42b123once 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
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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