is there a way that I can undo a git push which is not the last











up vote
0
down vote

favorite












my git commit order as below:



commit A ==> commit B(merge master) ==> commit C ==> commit D


the commit B used to pull and merge master, and after that commit C and D used to add/change file. Every commit has been push remote.



However when commit D push remote, the **master rollback **. Then my branch has some code which get from commit B(merge master) and the current master dont have for it has been rollback.



In order to keep consistent with master, I pull and merge master again but make no effect.
So is there a way I can remove commit B(merge master)? after that the commit flow look as:



commit A ==> commit C ==> commit D.


Every advice will be great appreciate.










share|improve this question






















  • do u have to revert the previous commit ?
    – Monis Majeed
    Nov 19 at 7:11










  • @MonisMajeed I expect to reserve commit A,C,D. and remove B
    – nail fei
    Nov 19 at 7:12










  • read here for more info stackoverflow.com/questions/34519665/…
    – CodeWizard
    Nov 19 at 8:08















up vote
0
down vote

favorite












my git commit order as below:



commit A ==> commit B(merge master) ==> commit C ==> commit D


the commit B used to pull and merge master, and after that commit C and D used to add/change file. Every commit has been push remote.



However when commit D push remote, the **master rollback **. Then my branch has some code which get from commit B(merge master) and the current master dont have for it has been rollback.



In order to keep consistent with master, I pull and merge master again but make no effect.
So is there a way I can remove commit B(merge master)? after that the commit flow look as:



commit A ==> commit C ==> commit D.


Every advice will be great appreciate.










share|improve this question






















  • do u have to revert the previous commit ?
    – Monis Majeed
    Nov 19 at 7:11










  • @MonisMajeed I expect to reserve commit A,C,D. and remove B
    – nail fei
    Nov 19 at 7:12










  • read here for more info stackoverflow.com/questions/34519665/…
    – CodeWizard
    Nov 19 at 8:08













up vote
0
down vote

favorite









up vote
0
down vote

favorite











my git commit order as below:



commit A ==> commit B(merge master) ==> commit C ==> commit D


the commit B used to pull and merge master, and after that commit C and D used to add/change file. Every commit has been push remote.



However when commit D push remote, the **master rollback **. Then my branch has some code which get from commit B(merge master) and the current master dont have for it has been rollback.



In order to keep consistent with master, I pull and merge master again but make no effect.
So is there a way I can remove commit B(merge master)? after that the commit flow look as:



commit A ==> commit C ==> commit D.


Every advice will be great appreciate.










share|improve this question













my git commit order as below:



commit A ==> commit B(merge master) ==> commit C ==> commit D


the commit B used to pull and merge master, and after that commit C and D used to add/change file. Every commit has been push remote.



However when commit D push remote, the **master rollback **. Then my branch has some code which get from commit B(merge master) and the current master dont have for it has been rollback.



In order to keep consistent with master, I pull and merge master again but make no effect.
So is there a way I can remove commit B(merge master)? after that the commit flow look as:



commit A ==> commit C ==> commit D.


Every advice will be great appreciate.







git






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 19 at 7:07









nail fei

1,165519




1,165519












  • do u have to revert the previous commit ?
    – Monis Majeed
    Nov 19 at 7:11










  • @MonisMajeed I expect to reserve commit A,C,D. and remove B
    – nail fei
    Nov 19 at 7:12










  • read here for more info stackoverflow.com/questions/34519665/…
    – CodeWizard
    Nov 19 at 8:08


















  • do u have to revert the previous commit ?
    – Monis Majeed
    Nov 19 at 7:11










  • @MonisMajeed I expect to reserve commit A,C,D. and remove B
    – nail fei
    Nov 19 at 7:12










  • read here for more info stackoverflow.com/questions/34519665/…
    – CodeWizard
    Nov 19 at 8:08
















do u have to revert the previous commit ?
– Monis Majeed
Nov 19 at 7:11




do u have to revert the previous commit ?
– Monis Majeed
Nov 19 at 7:11












@MonisMajeed I expect to reserve commit A,C,D. and remove B
– nail fei
Nov 19 at 7:12




@MonisMajeed I expect to reserve commit A,C,D. and remove B
– nail fei
Nov 19 at 7:12












read here for more info stackoverflow.com/questions/34519665/…
– CodeWizard
Nov 19 at 8:08




read here for more info stackoverflow.com/questions/34519665/…
– CodeWizard
Nov 19 at 8:08












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










Given that the branch and its merge commit are already pushed to the remote and are public, we should be cautious and avoid rewriting the history of this branch. A safe option would be to revert the merge commit B:



git checkout your_branch
git revert -m 1 <SHA-1 hash of B>


This assumes that you want to follow the first parent of the merge. If not, then use -m 2 instead. You may check git log to verify that the first parent follows back into commit A.



Note that this solution will make a new commit on top of your branch. To push these changes, a normal push will suffice:



git push origin your_branch





share|improve this answer





















  • then will my commit C and D lost?
    – nail fei
    Nov 19 at 7:33










  • Not at all. As mentioned, this option just functionally removes the merge commit B.
    – Tim Biegeleisen
    Nov 19 at 7:34











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',
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%2f53369818%2fis-there-a-way-that-i-can-undo-a-git-push-which-is-not-the-last%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








up vote
0
down vote



accepted










Given that the branch and its merge commit are already pushed to the remote and are public, we should be cautious and avoid rewriting the history of this branch. A safe option would be to revert the merge commit B:



git checkout your_branch
git revert -m 1 <SHA-1 hash of B>


This assumes that you want to follow the first parent of the merge. If not, then use -m 2 instead. You may check git log to verify that the first parent follows back into commit A.



Note that this solution will make a new commit on top of your branch. To push these changes, a normal push will suffice:



git push origin your_branch





share|improve this answer





















  • then will my commit C and D lost?
    – nail fei
    Nov 19 at 7:33










  • Not at all. As mentioned, this option just functionally removes the merge commit B.
    – Tim Biegeleisen
    Nov 19 at 7:34















up vote
0
down vote



accepted










Given that the branch and its merge commit are already pushed to the remote and are public, we should be cautious and avoid rewriting the history of this branch. A safe option would be to revert the merge commit B:



git checkout your_branch
git revert -m 1 <SHA-1 hash of B>


This assumes that you want to follow the first parent of the merge. If not, then use -m 2 instead. You may check git log to verify that the first parent follows back into commit A.



Note that this solution will make a new commit on top of your branch. To push these changes, a normal push will suffice:



git push origin your_branch





share|improve this answer





















  • then will my commit C and D lost?
    – nail fei
    Nov 19 at 7:33










  • Not at all. As mentioned, this option just functionally removes the merge commit B.
    – Tim Biegeleisen
    Nov 19 at 7:34













up vote
0
down vote



accepted







up vote
0
down vote



accepted






Given that the branch and its merge commit are already pushed to the remote and are public, we should be cautious and avoid rewriting the history of this branch. A safe option would be to revert the merge commit B:



git checkout your_branch
git revert -m 1 <SHA-1 hash of B>


This assumes that you want to follow the first parent of the merge. If not, then use -m 2 instead. You may check git log to verify that the first parent follows back into commit A.



Note that this solution will make a new commit on top of your branch. To push these changes, a normal push will suffice:



git push origin your_branch





share|improve this answer












Given that the branch and its merge commit are already pushed to the remote and are public, we should be cautious and avoid rewriting the history of this branch. A safe option would be to revert the merge commit B:



git checkout your_branch
git revert -m 1 <SHA-1 hash of B>


This assumes that you want to follow the first parent of the merge. If not, then use -m 2 instead. You may check git log to verify that the first parent follows back into commit A.



Note that this solution will make a new commit on top of your branch. To push these changes, a normal push will suffice:



git push origin your_branch






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 19 at 7:18









Tim Biegeleisen

210k1381129




210k1381129












  • then will my commit C and D lost?
    – nail fei
    Nov 19 at 7:33










  • Not at all. As mentioned, this option just functionally removes the merge commit B.
    – Tim Biegeleisen
    Nov 19 at 7:34


















  • then will my commit C and D lost?
    – nail fei
    Nov 19 at 7:33










  • Not at all. As mentioned, this option just functionally removes the merge commit B.
    – Tim Biegeleisen
    Nov 19 at 7:34
















then will my commit C and D lost?
– nail fei
Nov 19 at 7:33




then will my commit C and D lost?
– nail fei
Nov 19 at 7:33












Not at all. As mentioned, this option just functionally removes the merge commit B.
– Tim Biegeleisen
Nov 19 at 7:34




Not at all. As mentioned, this option just functionally removes the merge commit B.
– Tim Biegeleisen
Nov 19 at 7:34


















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53369818%2fis-there-a-way-that-i-can-undo-a-git-push-which-is-not-the-last%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

Ottavio Pratesi

Tricia Helfer

15 giugno