reverting back both working copy and commits

2 messages, 2 authors, 2016-06-15 · open the first message on its own page

reverting back both working copy and commits

From: Bahadir Balban <hidden>
Date: 2016-06-15 22:42:16

Hi,

I made some commits that later on I wanted to cancel. I did:

% git-branch master-2006-get-rid-of-commits

% git-reset --hard [sha1id]

where sha1id is the id of commit I want to revert back to. After this,
git-log points at the right commit (the one with [sha1id]) as the last
commit made. However, the working copy is left in the original state,
i.e with the unwanted changes.. How do I also revert the working
sources into an earlier state.

Because git-commit says "nothing to change" at this stage, git
checkout -f does not cure my problem. How do I also revert working
copy to earlier commit?

Thanks,
Bahadir

Re: reverting back both working copy and commits

From: Andreas Ericsson <hidden>
Date: 2016-06-15 22:42:16

Bahadir Balban wrote:
Hi,

I made some commits that later on I wanted to cancel. I did:

% git-branch master-2006-get-rid-of-commits

% git-reset --hard [sha1id]

where sha1id is the id of commit I want to revert back to. After this,
git-log points at the right commit (the one with [sha1id]) as the last
commit made. However, the working copy is left in the original state,
i.e with the unwanted changes.. How do I also revert the working
sources into an earlier state.
The branch where you do the reset is the one being reset, so you should 
have simply done the reset in the original branch without creating a new 
one. If you're nervous you're gonna screw up you can do this;

git checkout <branch-with-unwanted-commit>
git tag anchor
git reset --hard <commit-ish>

If you find you've landed on the wrong commit you can undo the change with

git reset --hard anchor

which will restore the branch to wherever you were prior to the first 
reset. Making an anchor tag is useful if you do several resets. You can 
use ORIG_HEAD to undo a single reset.

-- 
Andreas Ericsson                   andreas.ericsson@op5.se
OP5 AB                             www.op5.se
Tel: +46 8-230225                  Fax: +46 8-230231
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help