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.
git
add a comment |
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.
git
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
add a comment |
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.
git
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
git
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
add a comment |
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
add a comment |
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
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
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
add a comment |
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
add a comment |
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%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
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
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