# Set the repository as it was on an earlier commit

6 messages from 2009-12-25 to 2009-12-28. Participants: Sergio Belkin, Steven Noonan, Santi Béjar, Matthieu Moy.
Thread: https://gitlist.dev/t/22026

## Sergio Belkin, 2009-12-25 23:09

Subject: Set the repository as it was on an earlier commit
Message-ID: <8c6f7f450912251509i67da4665t78be0bb79f2c40d6@mail.gmail.com>
URL: https://gitlist.dev/e/8c6f7f450912251509i67da4665t78be0bb79f2c40d6%40mail.gmail.com

```
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, 2009-12-25 23:24

Subject: Re: Set the repository as it was on an earlier commit
Message-ID: <f488382f0912251524i12bf53a4xf381606705abff4b@mail.gmail.com>
URL: https://gitlist.dev/e/f488382f0912251524i12bf53a4xf381606705abff4b%40mail.gmail.com
In-Reply-To: <8c6f7f450912251509i67da4665t78be0bb79f2c40d6@mail.gmail.com>

```
On Fri, Dec 25, 2009 at 3:09 PM, Sergio Belkin <sebelk@gmail.com> wrote:
> 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, 2009-12-25 23:36

Subject: Re: Set the repository as it was on an earlier commit
Message-ID: <adf1fd3d0912251536kbf25272ob0ab8ee90e53861d@mail.gmail.com>
URL: https://gitlist.dev/e/adf1fd3d0912251536kbf25272ob0ab8ee90e53861d%40mail.gmail.com
In-Reply-To: <8c6f7f450912251509i67da4665t78be0bb79f2c40d6@mail.gmail.com>

```
On Sat, Dec 26, 2009 at 12:09 AM, Sergio Belkin <sebelk@gmail.com> wrote:
> 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, 2009-12-26 14:28

Subject: Re: Set the repository as it was on an earlier commit
Message-ID: <vpqiqbt95e7.fsf@bauges.imag.fr>
URL: https://gitlist.dev/e/vpqiqbt95e7.fsf%40bauges.imag.fr
In-Reply-To: <adf1fd3d0912251536kbf25272ob0ab8ee90e53861d@mail.gmail.com>

```
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/

```

## Sergio Belkin, 2009-12-28 04:19

Subject: Re: Set the repository as it was on an earlier commit
Message-ID: <8c6f7f450912272019t4b9c721dt2630a8d32607013e@mail.gmail.com>
URL: https://gitlist.dev/e/8c6f7f450912272019t4b9c721dt2630a8d32607013e%40mail.gmail.com
In-Reply-To: <vpqiqbt95e7.fsf@bauges.imag.fr>

```
2009/12/26 Matthieu Moy <Matthieu.Moy@grenoble-inp.fr>:
> 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, 2009-12-28 05:18

Subject: Fwd: Set the repository as it was on an earlier commit
Message-ID: <8c6f7f450912272118x384cd840j238b39efa9a87a3b@mail.gmail.com>
URL: https://gitlist.dev/e/8c6f7f450912272118x384cd840j238b39efa9a87a3b%40mail.gmail.com
In-Reply-To: <8c6f7f450912272019t4b9c721dt2630a8d32607013e@mail.gmail.com>

```
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>:
> 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 -

```
