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
579 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 Answer

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>


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

...