1

I have a config.js file in my repo. After working for a while... I added some sensitive information to that file, so I never commit it.

What I would like to do is to ignore this file, so never gets commited. However, I do not want the file to be removed from the remote repo, as if somebody wants to collaborate, I want them to have the base version of the config file.

I tried .gitignore but the file is still showed as 'modified' when I run a git status. If irrc I tried .git/info/exclude and I had a similar problem.

Also, --assume-unchanged is not intended for that. And it is not guaranteed that your file will not be committed.

David Torres
  • 1,767
  • 1
  • 16
  • 19
  • 1
    related: [What is the best practice for dealing with passwords in github?](http://stackoverflow.com/questions/2397822/what-is-the-best-practice-for-dealing-with-passwords-in-github) – Igor Milla Mar 14 '16 at 12:18
  • 2
    Write a commit hook that bails out of the commit if you accidentally try to commit this file. You can't really make git "ignore" this file, in this manner, but you can prevent it from getting committed. – Sam Varshavchik Mar 14 '16 at 12:19
  • @SamVarshavchik that sounds interesting. Could you write an example? – David Torres Mar 14 '16 at 12:22
  • I don't have to write an example, because many others have already written plenty of examples of commit hooks, which you can find on a very useful site called google.com – Sam Varshavchik Mar 14 '16 at 12:31
  • if you add the file to .gitignore should not appears in git status, did you update the .gitignore? "touch .gitignore" and later try git status. – cralfaro Mar 14 '16 at 17:11
  • @cralfaro The file appears because it is already in the remote repo – David Torres Mar 15 '16 at 11:04
  • @DavidTorres and you cant just remove from remote repo? and do a git commit to update the .gitignore file? – cralfaro Mar 15 '16 at 11:05
  • @cralfaro As stated in the question, I do not want to remove it from the remote repo. – David Torres Mar 15 '16 at 11:06
  • Then try to go to the repo, i guess will be some bitbucket/github, update the file there, and do a pull from remote in your branch, you will have the file update from develop, and then you can add into .gitignore – cralfaro Mar 15 '16 at 11:25
  • Why has this question never been asked before? Because Android Studio touches and alters a dozen files, this happens to me with _every project_ that I clone from a repository. – SMBiggs Jul 09 '16 at 23:49
  • @ScottBiggs For that, you can simply use .gitignore, as you do not need those Android Studio files in the repo. – David Torres Jul 14 '16 at 09:30

1 Answers1

3

That's the purpose of having a config.js.sample file with a base configuration which can be customized by anybody by renaming it to config.js. Which won't be committed if you put config.js on the ignore list.

mcserep
  • 3,231
  • 21
  • 36
  • If nobody comes up with an answer for the question in a couple of days, I think I should accept this one. – David Torres Mar 15 '16 at 11:05
  • When most version control system was designed, the concept was that a file (or object more generally) is tracked at a time if the system contains it and untracked otherwise. This does not meet the idea that you would like to have a file in the system but have the changes uncommitted, so untracked. Therefore I doubt there will be any designed solution for what you are looking for, sry :) – mcserep Mar 16 '16 at 13:55
  • This is not really a solution. It's a hack that works for this specific problem, and is therefore not useful to anyone else. Sigh. – SMBiggs Jul 09 '16 at 23:51
  • 1
    @ScottBiggs If you want to ignore file changes only locally, you are going against the paradigm of current version control systems and you are using it incorrectly. Therefore OP's request in general is not supported by Git (and other major revision control systems), the mentioned method is a classic and widely-used solution to commit sample config files into repositories. And that was the specific question. There is no solution in general, because it's not intended to be supported. – mcserep Jul 10 '16 at 14:12