Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

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

config - Git: How to ignore changes to a tracked file?

I have a file with database settings in my project which I have set to some defaults. The file is tracked by Git and checked in. Since this file will be edited with different values various developer machines, is there a way I can tell Git to ignore new changes to this file?

I tried adding the file to the .gitignore file, but since the file is tracked it isn't ignored. This is alright and good in other situations, but I am wondering if there is something I can do here?

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

One may use git update-index --skip-worktree FILE for this purpose.

It is similar to --assume-unchanged but, unlike --assume-unchanged, is not just an unpredictable performance trick.

To cancel --skip-worktree effects and unset the flag use --no-skip-worktree.

Downsides

  • This flag is for local repository only and cannot be pushed to the remote. Thus every clone that needs to ignore the file should do it manually.
  • You may face conflicts when switching to another branch or using git pull. (more details)

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

56.9k users

...