Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
2.1k views
in Technique[技术] by (71.8m points)

git - Assume unchanged, but only until the next change

How can I tell git to ignore the current modification made to a file foobar, but not any future modifications?

I have in my worktree a file to which I made a small change that I do not want to commit back. I could use git update-index --assume-unchanged foobar, but then git will ignore any other change made to this file.

I would like to tell git to ignore only the current modification to foobar, and warn me if it has been changed in any other way.

So, considered that update-index --assume-unchanged is not applicable in this case, is there another way to tell git to see foobar as unchanged only as long as it has the current content or the current mtime?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

The file is shared between two computers; it is being changed by an older version of an application that deletes configuration keys created by the newer version and that it does not understand.

Then it would be better to not version that file at all, and rather version:

  • a template of that file
  • 2 value files (one for each computer)
  • a script able to generate the final file (which would remain private)
  • a .gitignore to declare a content filer driver, a smudge script, which would, on checkout automatically trigger the script and generates the right config file, with the right values, detecting on which computer it is being run.

smudge

(image from "Customizing Git Attributes" from the Git Book)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...