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
632 views
in Technique[技术] by (71.8m points)

git - How to ignore files which are in repository?

I have a file (config.php), that is already commited to Git repository, but I want to ignore locally, i.e. I want that file to remain in repository, but force Git to ignore any changes to it.

I put the file into .gitignore, but it is still marked as changed and Git still is attempting to commit changes to it, every time I commit something. Any idea, what am I missing or doing wrong?

See Question&Answers more detail:os

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

1 Answer

0 votes
by (71.8m points)

If the file is still displayed in the status, even though it is in the .gitignore, make sure it isn't already tracked.

git rm --cached config.php

If you just want to ignore it locally, you could also make it ignored by the git status:

git update-index --assume-unchanged config.php

As commented, do note that using --assume-unchanged might cause unwanted data loss as git stash resets the "ignored" files to the state in upstream, undoing local changes, without a warning or saving.


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

Just Browsing Browsing

[1] html - How to create even cell spacing within a

2.1m questions

2.1m answers

60 comments

56.8k users

...