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

version control - git - Is it possible to exclude file from `git push`, but keep them in the local repository?

In my home directory I have files in a local git repository, because I want track them all under version control.

Most of these files I want to push to a remote repository, but a few I want to keep in my local repository only (they contain mildly sensitive information).

How can I achieve this with git? Can I configure a ".gitignore-for-push" file? I cannot use the local .gitignore file, because it would exclude these files completely from being tracked.

ps: I am aware of question Is there an exclude file-equivalent..., but the answer goes down the .gitignore path which I cannot use. The other question Exclude specific files when pushing... answers only a specific case for git+heroku, not git alone.

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 go ahead and actually track these files (sans the sensitive info), but then use:

git update-index --assume-unchanged <file>

on each file. Then you can go ahead and add the sensitive info to each file, but Git will not see the file as changed, and not try to commit (and thus push) that sensitive info.

To get Git to update the info again, you'd use:

git update-index --no-assume-unchanged <file>


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

...