threads / discuss / 9366

Forcing rewrite of files in working tree

Subject: Forcing rewrite of files in working tree

## tl;dr

4 messages between Aug 3, 2007 and Aug 3, 2007.

replies: 3people: 3as markdown or json

Andy Parkins· Aug 3, 2007, 12:45 UTC · lore
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· Aug 3, 2007, 12:58 UTC · re: Andy Parkins · lore

Re: Forcing rewrite of files in working tree

Andy Parkins wrote:
Show 20 quoted lines
> 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· Aug 3, 2007, 13:39 UTC · re: Rogan Dawes · lore

Re: Forcing rewrite of files in working tree

On Friday 2007 August 03, Rogan Dawes wrote:
Show 7 quoted lines
> > 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· Aug 3, 2007, 19:55 UTC · re: Andy Parkins · lore

Re: Forcing rewrite of files in working tree

On Fri, 3 Aug 2007, Andy Parkins wrote:
Show 11 quoted lines
> 
> 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

← back to recent threads