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

git - How do I .gitignore and delete an already committed file without affecting other working copies?

I have a bare repository and two working copies - one on my machine, the other on the server.
It turned out that I have to .gitignore a certain file that has to be specific for every machine. Let's call it 'settings.py'. This file is already committed.

I did put 'settings.py' in .gitignore to ignore it. When I now change the file on my machine git status still tells me

modified:  settings.py

I figured out that I have to remove settings.py like this:

git rm --cached settings.py

Then git add ., followed by git commit.

But when I now push this to the bare repo and pull it to the working copy on the server, settings.py is deleted there - which is bad because I have to keep this specific settings.py.

I figured that I just could make a copy of settings.py and put it back in once it is deleted, but I feel like there has to be a better way of doing this.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

You can tell git to completely ignore changes to tracked files without having to remove them. Use this command:

git update-index --assume-unchanged [FILENAME]

Then if you want to track the file later:

git update-index --no-assume-unchanged [FILENAME]

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

...