Skip to contentSkip to conversation

Forcing rewrite of files in working tree

DISCUSSION Andy Parkins 3 participants 4 messages Jun 15, 2016

lore
Share & tools
lore
#0 lore raw

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

Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET
[email protected]
#1 lore raw
Quoted 9 lines · Andy Parkins

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

#2 lore raw
Quoted 7 lines · Rogan Dawes
Quoted 5 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

Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET
[email protected]
#3 lore raw
In reply to Andy Parkins
Quoted 11 lines · Andy Parkins

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