threads / discuss / 22026

Set the repository as it was on an earlier commit

Subject: Set the repository as it was on an earlier commit

## tl;dr

6 messages between Dec 25, 2009 and Dec 28, 2009.

replies: 5people: 4as markdown or json

Sergio Belkin· Dec 25, 2009, 23:09 UTC · lore
Hi,
Firstly merry Christmas everyone.

I am somewhat new to git, and I've found great, but still I have some doubts about it, let's say I have the following repo with:

A---B---C---D
Being A the first commit,  B the second one an D the last one.
How I do to go back to let's say... B commit status, I mean somewhat as follows:
A---B---C---D---B'
B' would be the same as B. I am not asking to do something so:
A---B---C---D to A---B losing C and D commits,
I'd like to keep on history C and D commits, can git to do that?
Thanks in advance!
-- 
--
Open Kairos http://www.sergiobelkin.com
Watch More TV http://sebelk.blogspot.com
Sergio Belkin -
Steven Noonan· Dec 25, 2009, 23:24 UTC · re: Sergio Belkin · lore

Re: Set the repository as it was on an earlier commit

On Fri, Dec 25, 2009 at 3:09 PM, Sergio Belkin <sebelk@gmail.com> wrote:
Show 23 quoted lines
> Hi,
>
> Firstly merry Christmas everyone.
>
> I am somewhat new to git, and I've found great, but still I have some
> doubts about it, let's say I have the following repo with:
>
> A---B---C---D
>
> Being A the first commit,  B the second one an D the last one.
>
> How I do to go back to let's say... B commit status, I mean somewhat as follows:
>
> A---B---C---D---B'
>
> B' would be the same as B. I am not asking to do something so:
>
> A---B---C---D to A---B losing C and D commits,
>
> I'd like to keep on history C and D commits, can git to do that?
>
> Thanks in advance!
>

git revert D git revert C

Maybe? It would create two revert commits, but it would get you back to the state of B.

- Steven
Santi Béjar· Dec 25, 2009, 23:36 UTC · re: Sergio Belkin · lore

Re: Set the repository as it was on an earlier commit

On Sat, Dec 26, 2009 at 12:09 AM, Sergio Belkin <sebelk@gmail.com> wrote:
Show 20 quoted lines
> Hi,
>
> Firstly merry Christmas everyone.
>
> I am somewhat new to git, and I've found great, but still I have some
> doubts about it, let's say I have the following repo with:
>
> A---B---C---D
>
> Being A the first commit,  B the second one an D the last one.
>
> How I do to go back to let's say... B commit status, I mean somewhat as follows:
>
> A---B---C---D---B'
>
> B' would be the same as B. I am not asking to do something so:
>
> A---B---C---D to A---B losing C and D commits,
>
> I'd like to keep on history C and D commits, can git to do that?

I don't know if it is possible with porcelain commands, but with plumbing you can:

# begin with a clean working dir git read-tree B git commit git reset --hard

HTH, Santi

Matthieu Moy· Dec 26, 2009, 14:28 UTC · re: Santi Béjar · lore

Re: Set the repository as it was on an earlier commit

Santi Béjar <santi@agolina.net> writes:
Show 7 quoted lines
> I don't know if it is possible with porcelain commands, but with
> plumbing you can:
>
> # begin with a clean working dir
> git read-tree B
> git commit
> git reset --hard
I guess
(at the root of the repo)

git checkout B -- . # git status if you want to check. git commit

does this. The "-- ." part of "git checkout" asks Git to checkout the files, but the path limiter prevents it from updating HEAD, so the HEAD still points to the tip of the branch.

-- 
Matthieu Moy
http://www-verimag.imag.fr/~moy/
Sergio Belkin· Dec 28, 2009, 04:19 UTC · re: Matthieu Moy · lore

Re: Set the repository as it was on an earlier commit

2009/12/26 Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>:
Show 26 quoted lines
> Santi Béjar <santi@agolina.net> writes:
>
>> I don't know if it is possible with porcelain commands, but with
>> plumbing you can:
>>
>> # begin with a clean working dir
>> git read-tree B
>> git commit
>> git reset --hard
>
> I guess
>
> (at the root of the repo)
>
> git checkout B -- .
> # git status if you want to check.
> git commit
>
> does this. The "-- ." part of "git checkout" asks Git to checkout the
> files, but the path limiter prevents it from updating HEAD, so the
> HEAD still points to the tip of the branch.
>
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
>

Sorry but really answer given by Steven was better, because last one omit the case when B had less files that D for example...

Thanks everyone
-- 
--
Open Kairos http://www.sergiobelkin.com
Watch More TV http://sebelk.blogspot.com
Sergio Belkin -
Sergio Belkin· Dec 28, 2009, 05:18 UTC · re: Sergio Belkin · lore

Fwd: Set the repository as it was on an earlier commit

Ooops I wanted to say Santi answer was the best
---------- Forwarded message ----------
From: Sergio Belkin <sebelk@gmail.com>
Date: 2009/12/28
Subject: Re: Set the repository as it was on an earlier commit
To: git@vger.kernel.org
2009/12/26 Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>:
Show 26 quoted lines
> Santi Béjar <santi@agolina.net> writes:
>
>> I don't know if it is possible with porcelain commands, but with
>> plumbing you can:
>>
>> # begin with a clean working dir
>> git read-tree B
>> git commit
>> git reset --hard
>
> I guess
>
> (at the root of the repo)
>
> git checkout B -- .
> # git status if you want to check.
> git commit
>
> does this. The "-- ." part of "git checkout" asks Git to checkout the
> files, but the path limiter prevents it from updating HEAD, so the
> HEAD still points to the tip of the branch.
>
> --
> Matthieu Moy
> http://www-verimag.imag.fr/~moy/
>

Sorry but really answer given by Steven was better, because last one omit the case when B had less files that D for example...

Thanks everyone

-- -- Open Kairos http://www.sergiobelkin.com Watch More TV http://sebelk.blogspot.com Sergio Belkin -

-- 
--
Open Kairos http://www.sergiobelkin.com
Watch More TV http://sebelk.blogspot.com
Sergio Belkin -

← back to recent threads