I want to make an java application. This is stored on gitHub (so uses git for versioning). Now this programm uses apikeys in example from Google. I want to hide this Api key in the versioning system (so that no one other can use it).
I've read something about the .gitignore file, but i don't want to delete the whole file from versioning. I only want to hide the apiKey from others to see.
I read following thread and I think this is what I'm searching for, but I really have no idea how to do this.
You cannot version the file and hide it from others. The ID of a commit is based in part on the ID of the commit file tree, which is based on the contents of that tree -- file names and contents. If you change the contents of a file, you change its identity in Git. When you change its identity, you change the identity of the tree it's contained in, all the way up to the commit.
In short, no. The ID of every commit containing this file will be based upon the contents of that file. The only way to hide the file from others who will have access to the repository is to never add it to the repository in the first place.
(If you have not yet published the repository, you can rewrite history using git filter-branch
to remove all occurrences of the file. Note that this will, as described above, change the identity of many commits.)