# finding if a commit is needed

3 messages from 2010-07-28 to 2010-07-30. Participants: Geoff Russell, Jonathan Nieder.
Thread: https://gitlist.dev/t/24548

## Geoff Russell, 2010-07-28 08:53

Subject: finding if a commit is needed
Message-ID: <AANLkTin4o=uNBFELYMb8TDA=taGJyqpLvgxZcPFr+Pq+@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTin4o%3DuNBFELYMb8TDA%3DtaGJyqpLvgxZcPFr%2BPq%2B%40mail.gmail.com

```
We have an interface which "rolls back" commits to a previous time in
a set of data files using read-tree.

Works great ... but sometimes there are files which have
been changed in the working tree which cause read-tree to fail.
The files should have been committed but weren't.
"git read-tree -i" isn't appropriate because
we want to commit these files before the read-tree rolls
them back ... because they are changes which might be
resurrected and we don't want to lose them altogether.

So ...

       git commit -a -m "something" && git read-tree ...

Doesn't work when there are no files which need committing ...

       git commit -a -m "something" || git read-tree ...

Doesn't work when there are.

Is there something which can test whether a commit is needed?

I define "needed" as meaning when git commit -a would make a non-identical
commit.

Many thanks,
Geoff.

```

## Jonathan Nieder, 2010-07-29 00:06

Subject: Re: finding if a commit is needed
Message-ID: <20100729000647.GB29156@dert.cs.uchicago.edu>
URL: https://gitlist.dev/e/20100729000647.GB29156%40dert.cs.uchicago.edu
In-Reply-To: <AANLkTin4o=uNBFELYMb8TDA=taGJyqpLvgxZcPFr+Pq+@mail.gmail.com>

```
Geoff Russell wrote:

> Is there something which can test whether a commit is needed?
> 
> I define "needed" as meaning when git commit -a would make a non-identical
> commit.

Maybe "git diff --exit-code HEAD"?

Regards,
Jonathan

```

## Geoff Russell, 2010-07-30 10:16

Subject: Re: finding if a commit is needed
Message-ID: <AANLkTinvLVJbnZ4ZnrszV1taDUS3B-0aWYoD1Q5UyFtA@mail.gmail.com>
URL: https://gitlist.dev/e/AANLkTinvLVJbnZ4ZnrszV1taDUS3B-0aWYoD1Q5UyFtA%40mail.gmail.com
In-Reply-To: <20100729000647.GB29156@dert.cs.uchicago.edu>

```
On Thu, Jul 29, 2010 at 9:36 AM, Jonathan Nieder <jrnieder@gmail.com> wrote:
> Geoff Russell wrote:
>
>> Is there something which can test whether a commit is needed?
>>
>> I define "needed" as meaning when git commit -a would make a non-identical
>> commit.
>
> Maybe "git diff --exit-code HEAD"?

Thanks ... "git diff --quiet || echo differences"

Cheers,
Geoff.

>
> Regards,
> Jonathan
>



-- 
6 Fifth Ave,
St Morris, S.A. 5068
Australia
Ph: 041 8805 184 / 08 8332 5069
http://perfidy.com.au

```
