# Forcing rewrite of files in working tree

4 messages from 2007-08-03 to 2007-08-03. Participants: Andy Parkins, Rogan Dawes, Linus Torvalds.
Thread: https://gitlist.dev/t/9366

## Andy Parkins, 2007-08-03 12:45

Subject: Forcing rewrite of files in working tree
Message-ID: <200708031345.47127.andyparkins@gmail.com>
URL: https://gitlist.dev/e/200708031345.47127.andyparkins%40gmail.com

```
Hello,

I want to write a little recipe in a Makefile that ensures the $Id$ field in a 
series of text files is correct.  In case it's relevant, I'm including a load 
of asciidoc files as subsections into one master file; each file has a $Id$ 
field in the header, which very nicely prints out at the start of each 
section.  However, the $Id$ field is only written on checkout (not on checkin 
for fairly obvious reasons).  That means that for any files I've changed, the 
$Id$ is wrong.  Before I generate output using ASCIIdoc I'd like to ensure 
the $Id$ is correct.

How do I do it?

The only method I've found is to delete the file in the work tree then do 
git-checkout again.  Even with -f, if the file is not changed git doesn't 
perform a checkout again, so git-checkout -f is not sufficient.  I assume I 
can do what I want with some clever plumbing, but I don't know any 
plumbing. :-)



Andy
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com

```

## Rogan Dawes, 2007-08-03 12:58

Subject: Re: Forcing rewrite of files in working tree
Message-ID: <46B3268C.7060707@dawes.za.net>
URL: https://gitlist.dev/e/46B3268C.7060707%40dawes.za.net
In-Reply-To: <200708031345.47127.andyparkins@gmail.com>

```
Andy Parkins wrote:
> Hello,
> 
> I want to write a little recipe in a Makefile that ensures the $Id$ field in a 
> series of text files is correct.  In case it's relevant, I'm including a load 
> of asciidoc files as subsections into one master file; each file has a $Id$ 
> field in the header, which very nicely prints out at the start of each 
> section.  However, the $Id$ field is only written on checkout (not on checkin 
> for fairly obvious reasons).  That means that for any files I've changed, the 
> $Id$ is wrong.  Before I generate output using ASCIIdoc I'd like to ensure 
> the $Id$ is correct.
> 
> How do I do it?
> 
> The only method I've found is to delete the file in the work tree then do 
> git-checkout again.  Even with -f, if the file is not changed git doesn't 
> perform a checkout again, so git-checkout -f is not sufficient.  I assume I 
> can do what I want with some clever plumbing, but I don't know any 
> plumbing. :-)
> 
> Andy

$ git reset --hard

?

Rogan

```

## Andy Parkins, 2007-08-03 13:39

Subject: Re: Forcing rewrite of files in working tree
Message-ID: <200708031439.29721.andyparkins@gmail.com>
URL: https://gitlist.dev/e/200708031439.29721.andyparkins%40gmail.com
In-Reply-To: <46B3268C.7060707@dawes.za.net>

```
On Friday 2007 August 03, Rogan Dawes wrote:

> > The only method I've found is to delete the file in the work tree then do
> > git-checkout again.  Even with -f, if the file is not changed git doesn't
> > perform a checkout again, so git-checkout -f is not sufficient.  I assume
> > I can do what I want with some clever plumbing, but I don't know any
> > plumbing. :-)
>
> $ git reset --hard

I think that that suffers the same as "git-checkout -f"; if it doesn't see 
changes then it doesn't reread.  Also, it's not possible to do per-file:

$ git reset --hard HEAD somefile.txt
Cannot do partial --hard reset.

Which is a necessity really; I don't want to accidentally overwrite work 
that's not yet checked in in the rest of the tree.

Is git-checkout-index the thing I'm looking for?  I'm wondering if the "-n" 
switch is the trick?


Andy
-- 
Dr Andy Parkins, M Eng (hons), MIET
andyparkins@gmail.com

```

## Linus Torvalds, 2007-08-03 19:55

Subject: Re: Forcing rewrite of files in working tree
Message-ID: <alpine.LFD.0.999.0708031251130.8184@woody.linux-foundation.org>
URL: https://gitlist.dev/e/alpine.LFD.0.999.0708031251130.8184%40woody.linux-foundation.org
In-Reply-To: <200708031345.47127.andyparkins@gmail.com>

```


On Fri, 3 Aug 2007, Andy Parkins wrote:
> 
> I want to write a little recipe in a Makefile that ensures the $Id$ field in a 
> series of text files is correct.  In case it's relevant, I'm including a load 
> of asciidoc files as subsections into one master file; each file has a $Id$ 
> field in the header, which very nicely prints out at the start of each 
> section.  However, the $Id$ field is only written on checkout (not on checkin 
> for fairly obvious reasons).  That means that for any files I've changed, the 
> $Id$ is wrong.  Before I generate output using ASCIIdoc I'd like to ensure 
> the $Id$ is correct.
> 
> How do I do it?

Something like

	git read-tree HEAD
	git checkout -f

should do it.

The read-tree basically invalidated the index, by forcing it to the HEAD 
tree (and *without* doing a merge with the old index, so it doesn't get 
any of the size/date/inode fields right). And at that point, git thinks 
that all files are stale, so "git checkout -f" will force the checkout for 
all of them.

I'm sure you can do it other ways too, but that's the "obvious" one.

			Linus

```
