Git cancel a revert
In git let say I commit A and B
A---[B]
But then I revert with
git revert HEAD
So I am there now:
[A]---B
How do I cancel my revert so that I can go back to B?
git version-control
add a comment |
In git let say I commit A and B
A---[B]
But then I revert with
git revert HEAD
So I am there now:
[A]---B
How do I cancel my revert so that I can go back to B?
git version-control
I am not sure how the term "revert" is used in Git means, but in general, reverting means to overwrite any local changes. So only an undelete tool could help at all, but there are little chances.
– Andreas
Jul 7 '10 at 22:25
2
@Andreas: In Git, a "revert" is a new commit that reverses the application of some earlier commit.
– Greg Hewgill
Jul 7 '10 at 22:30
@Greg: Thanks for clearification.
– Andreas
Jul 7 '10 at 22:31
2
Your picture is inaccurate. After the revert, you haveA---B---!B
, where!B
is the commit revertingB
. Greg's two answers, respectively, create a commit!!B
reverting!B
or return you toB
.
– Cascabel
Jul 8 '10 at 0:05
"git reset --hard REF", replace "REF" with the reference or SHA you want to get back to. sethrobertson.github.io/GitFixUm/fixup.html
– phoad
Dec 11 '13 at 20:17
add a comment |
In git let say I commit A and B
A---[B]
But then I revert with
git revert HEAD
So I am there now:
[A]---B
How do I cancel my revert so that I can go back to B?
git version-control
In git let say I commit A and B
A---[B]
But then I revert with
git revert HEAD
So I am there now:
[A]---B
How do I cancel my revert so that I can go back to B?
git version-control
git version-control
edited Apr 20 '14 at 21:57
user456814
asked Jul 7 '10 at 22:21
mathkmathk
4,78743462
4,78743462
I am not sure how the term "revert" is used in Git means, but in general, reverting means to overwrite any local changes. So only an undelete tool could help at all, but there are little chances.
– Andreas
Jul 7 '10 at 22:25
2
@Andreas: In Git, a "revert" is a new commit that reverses the application of some earlier commit.
– Greg Hewgill
Jul 7 '10 at 22:30
@Greg: Thanks for clearification.
– Andreas
Jul 7 '10 at 22:31
2
Your picture is inaccurate. After the revert, you haveA---B---!B
, where!B
is the commit revertingB
. Greg's two answers, respectively, create a commit!!B
reverting!B
or return you toB
.
– Cascabel
Jul 8 '10 at 0:05
"git reset --hard REF", replace "REF" with the reference or SHA you want to get back to. sethrobertson.github.io/GitFixUm/fixup.html
– phoad
Dec 11 '13 at 20:17
add a comment |
I am not sure how the term "revert" is used in Git means, but in general, reverting means to overwrite any local changes. So only an undelete tool could help at all, but there are little chances.
– Andreas
Jul 7 '10 at 22:25
2
@Andreas: In Git, a "revert" is a new commit that reverses the application of some earlier commit.
– Greg Hewgill
Jul 7 '10 at 22:30
@Greg: Thanks for clearification.
– Andreas
Jul 7 '10 at 22:31
2
Your picture is inaccurate. After the revert, you haveA---B---!B
, where!B
is the commit revertingB
. Greg's two answers, respectively, create a commit!!B
reverting!B
or return you toB
.
– Cascabel
Jul 8 '10 at 0:05
"git reset --hard REF", replace "REF" with the reference or SHA you want to get back to. sethrobertson.github.io/GitFixUm/fixup.html
– phoad
Dec 11 '13 at 20:17
I am not sure how the term "revert" is used in Git means, but in general, reverting means to overwrite any local changes. So only an undelete tool could help at all, but there are little chances.
– Andreas
Jul 7 '10 at 22:25
I am not sure how the term "revert" is used in Git means, but in general, reverting means to overwrite any local changes. So only an undelete tool could help at all, but there are little chances.
– Andreas
Jul 7 '10 at 22:25
2
2
@Andreas: In Git, a "revert" is a new commit that reverses the application of some earlier commit.
– Greg Hewgill
Jul 7 '10 at 22:30
@Andreas: In Git, a "revert" is a new commit that reverses the application of some earlier commit.
– Greg Hewgill
Jul 7 '10 at 22:30
@Greg: Thanks for clearification.
– Andreas
Jul 7 '10 at 22:31
@Greg: Thanks for clearification.
– Andreas
Jul 7 '10 at 22:31
2
2
Your picture is inaccurate. After the revert, you have
A---B---!B
, where !B
is the commit reverting B
. Greg's two answers, respectively, create a commit !!B
reverting !B
or return you to B
.– Cascabel
Jul 8 '10 at 0:05
Your picture is inaccurate. After the revert, you have
A---B---!B
, where !B
is the commit reverting B
. Greg's two answers, respectively, create a commit !!B
reverting !B
or return you to B
.– Cascabel
Jul 8 '10 at 0:05
"git reset --hard REF", replace "REF" with the reference or SHA you want to get back to. sethrobertson.github.io/GitFixUm/fixup.html
– phoad
Dec 11 '13 at 20:17
"git reset --hard REF", replace "REF" with the reference or SHA you want to get back to. sethrobertson.github.io/GitFixUm/fixup.html
– phoad
Dec 11 '13 at 20:17
add a comment |
3 Answers
3
active
oldest
votes
You have two general choices:
- Revert the revert commit (creating a second revert commit that takes you back to the original)
- Throw away the revert commit with
git reset --hard HEAD^
The second option is only appropriate if you have not pushed your changes anywhere else. In fact, if you haven't pushed your first revert commit anywhere yet, you can simply use
git reset --hard
to roll back without creating any revert commits at all.
1
Don't do the reset --hard just like I did, I lost all foreign files in my repo!
– Benoît
Jan 1 '18 at 10:55
add a comment |
If you haven't done it completely, i.e., in gitbash
you see something like:
Username@Host MINGW64 /d/code/your-project (feature|REVERTING)
then you can use git revert --abort
to abort.
If you have done it.. just don't reset, the changes are still there. Use git reset
to change the state. Instead of --hard
, you can also use --soft
(keep all the changes).
git reset --soft HEAD^ // discard the last commit, keeping all the changes after that
add a comment |
As you create a new commit
which reverts another commit
you can threat it like a commit.
So basically you have many choices, such as
git rebase -i
(remove the revert commit)
git reset --hard <commitID>
(reset to the commit before the revert, you'll lose all local changes)
git reset --soft <commitID>
(same as above but keeps local changes)
- technically you can use
git revert <commitId>
to revert your revert
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%2f3199366%2fgit-cancel-a-revert%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have two general choices:
- Revert the revert commit (creating a second revert commit that takes you back to the original)
- Throw away the revert commit with
git reset --hard HEAD^
The second option is only appropriate if you have not pushed your changes anywhere else. In fact, if you haven't pushed your first revert commit anywhere yet, you can simply use
git reset --hard
to roll back without creating any revert commits at all.
1
Don't do the reset --hard just like I did, I lost all foreign files in my repo!
– Benoît
Jan 1 '18 at 10:55
add a comment |
You have two general choices:
- Revert the revert commit (creating a second revert commit that takes you back to the original)
- Throw away the revert commit with
git reset --hard HEAD^
The second option is only appropriate if you have not pushed your changes anywhere else. In fact, if you haven't pushed your first revert commit anywhere yet, you can simply use
git reset --hard
to roll back without creating any revert commits at all.
1
Don't do the reset --hard just like I did, I lost all foreign files in my repo!
– Benoît
Jan 1 '18 at 10:55
add a comment |
You have two general choices:
- Revert the revert commit (creating a second revert commit that takes you back to the original)
- Throw away the revert commit with
git reset --hard HEAD^
The second option is only appropriate if you have not pushed your changes anywhere else. In fact, if you haven't pushed your first revert commit anywhere yet, you can simply use
git reset --hard
to roll back without creating any revert commits at all.
You have two general choices:
- Revert the revert commit (creating a second revert commit that takes you back to the original)
- Throw away the revert commit with
git reset --hard HEAD^
The second option is only appropriate if you have not pushed your changes anywhere else. In fact, if you haven't pushed your first revert commit anywhere yet, you can simply use
git reset --hard
to roll back without creating any revert commits at all.
edited May 15 '15 at 14:31
pal4life
1,52022646
1,52022646
answered Jul 7 '10 at 22:29
Greg HewgillGreg Hewgill
670k14410131166
670k14410131166
1
Don't do the reset --hard just like I did, I lost all foreign files in my repo!
– Benoît
Jan 1 '18 at 10:55
add a comment |
1
Don't do the reset --hard just like I did, I lost all foreign files in my repo!
– Benoît
Jan 1 '18 at 10:55
1
1
Don't do the reset --hard just like I did, I lost all foreign files in my repo!
– Benoît
Jan 1 '18 at 10:55
Don't do the reset --hard just like I did, I lost all foreign files in my repo!
– Benoît
Jan 1 '18 at 10:55
add a comment |
If you haven't done it completely, i.e., in gitbash
you see something like:
Username@Host MINGW64 /d/code/your-project (feature|REVERTING)
then you can use git revert --abort
to abort.
If you have done it.. just don't reset, the changes are still there. Use git reset
to change the state. Instead of --hard
, you can also use --soft
(keep all the changes).
git reset --soft HEAD^ // discard the last commit, keeping all the changes after that
add a comment |
If you haven't done it completely, i.e., in gitbash
you see something like:
Username@Host MINGW64 /d/code/your-project (feature|REVERTING)
then you can use git revert --abort
to abort.
If you have done it.. just don't reset, the changes are still there. Use git reset
to change the state. Instead of --hard
, you can also use --soft
(keep all the changes).
git reset --soft HEAD^ // discard the last commit, keeping all the changes after that
add a comment |
If you haven't done it completely, i.e., in gitbash
you see something like:
Username@Host MINGW64 /d/code/your-project (feature|REVERTING)
then you can use git revert --abort
to abort.
If you have done it.. just don't reset, the changes are still there. Use git reset
to change the state. Instead of --hard
, you can also use --soft
(keep all the changes).
git reset --soft HEAD^ // discard the last commit, keeping all the changes after that
If you haven't done it completely, i.e., in gitbash
you see something like:
Username@Host MINGW64 /d/code/your-project (feature|REVERTING)
then you can use git revert --abort
to abort.
If you have done it.. just don't reset, the changes are still there. Use git reset
to change the state. Instead of --hard
, you can also use --soft
(keep all the changes).
git reset --soft HEAD^ // discard the last commit, keeping all the changes after that
answered Dec 31 '18 at 9:04
WesternGunWesternGun
2,0041435
2,0041435
add a comment |
add a comment |
As you create a new commit
which reverts another commit
you can threat it like a commit.
So basically you have many choices, such as
git rebase -i
(remove the revert commit)
git reset --hard <commitID>
(reset to the commit before the revert, you'll lose all local changes)
git reset --soft <commitID>
(same as above but keeps local changes)
- technically you can use
git revert <commitId>
to revert your revert
add a comment |
As you create a new commit
which reverts another commit
you can threat it like a commit.
So basically you have many choices, such as
git rebase -i
(remove the revert commit)
git reset --hard <commitID>
(reset to the commit before the revert, you'll lose all local changes)
git reset --soft <commitID>
(same as above but keeps local changes)
- technically you can use
git revert <commitId>
to revert your revert
add a comment |
As you create a new commit
which reverts another commit
you can threat it like a commit.
So basically you have many choices, such as
git rebase -i
(remove the revert commit)
git reset --hard <commitID>
(reset to the commit before the revert, you'll lose all local changes)
git reset --soft <commitID>
(same as above but keeps local changes)
- technically you can use
git revert <commitId>
to revert your revert
As you create a new commit
which reverts another commit
you can threat it like a commit.
So basically you have many choices, such as
git rebase -i
(remove the revert commit)
git reset --hard <commitID>
(reset to the commit before the revert, you'll lose all local changes)
git reset --soft <commitID>
(same as above but keeps local changes)
- technically you can use
git revert <commitId>
to revert your revert
edited Dec 31 '18 at 11:22
answered Dec 31 '18 at 11:13
elpelp
353115
353115
add a comment |
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%2f3199366%2fgit-cancel-a-revert%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
I am not sure how the term "revert" is used in Git means, but in general, reverting means to overwrite any local changes. So only an undelete tool could help at all, but there are little chances.
– Andreas
Jul 7 '10 at 22:25
2
@Andreas: In Git, a "revert" is a new commit that reverses the application of some earlier commit.
– Greg Hewgill
Jul 7 '10 at 22:30
@Greg: Thanks for clearification.
– Andreas
Jul 7 '10 at 22:31
2
Your picture is inaccurate. After the revert, you have
A---B---!B
, where!B
is the commit revertingB
. Greg's two answers, respectively, create a commit!!B
reverting!B
or return you toB
.– Cascabel
Jul 8 '10 at 0:05
"git reset --hard REF", replace "REF" with the reference or SHA you want to get back to. sethrobertson.github.io/GitFixUm/fixup.html
– phoad
Dec 11 '13 at 20:17