问题
I have a google_oauth_server.xml file in my project. It contains a client id, which I would like to not get checked into the repository.
<?xml version="1.0" encoding="utf-8"?>
<!-- Do not split into debug and release, as there is one server-->
<resources>
<string name="google_server_client_id" templateMergeStrategy="preserve" translatable="false">
---my-code--
</string>
</resources>
Instead, I want the file to exist in the repo, but with the words YOUR CODE HERE
instead of the code.
I tried committing a file with the words YOUR_CODE_HERE
instead of the code, then changing the words to my actual client id, and then adding the file to .gitignore
to prevent it from getting committed, but it does not work, and git always tries to commit the file with the client id.
回答1:
git-update-index:
Users often try to use the assume-unchanged and skip-worktree bits to tell Git to ignore changes to files that are tracked. This does not work as expected, since Git may still check working tree files against the index when performing certain operations. In general, Git does not provide a way to ignore changes to tracked files, so alternate solutions are recommended.
For example, if the file you want to change is some sort of config file, the repository can include a sample config file that can then be copied into the ignored name and modified. The repository can even include a script to treat the sample file as a template, modifying and copying it automatically.
来源:https://stackoverflow.com/questions/60995052/keep-existing-files-from-getting-updates-in-git