Reputation: 1357
I've a committed file "build.properties", this file has to be on our project repository as it contains important build information.
Sometime some developer performing some local testing, change the content of this file, and then they commit the changes by mistake (by simply staging all the changes they made, build.properties included).
Now I would like, somehow, to ignore all the local changes made to this file in order to avoid this situation that keep braking the build, so for example when the developer will run a *git add ** or a git commit -a, that file won't be included in the staged file.
I did already some research, but till now I cannot find any solution compatible with what i'm looking for, considering that the operation needs to be applied remotely, for example I can use the .git/info/exclude folder, but then every time a new developer will clone the repository, he will have to set the .git/info/exclude again, and I would like to avoid this.
Moreover, .gitignore works just with un-tracked file, if I add a tracked file to .gitignore, it won't be ignore at all. I found some persons suggesting to use .gitignore in combination with git rm --cached then re-add the files, but once the file were re-added to the tree, the changes were keeping being tracked, also reading from offical GIT doc, .gitignore does not look to be suitable for my needs.
Any solution in mind? Thanks!
UPDATE
I'm a big fan of SVN, and more I know GIT, more I appreciate SubVersion.
So I guess, the answer to my question is GIT does not provide any way to achieve something like this...
Agree that would not be the best of the practices and that there are other ways to achieve what i'm asking without managing it with the famous source control tool GIT, but my intention is still something quite common that we can face in many different contexts.
I mean GIT provide ways to get around most of the standard practices and principles, for example I can't change a remote history for principle, but GIT gave me the --force to achieve this, so I wonder why it does not provide an easy way to get around my issue too.
Upvotes: 3
Views: 1630
Reputation: 2172
The better way would be to have multiple build.properties
for different environments.
Example: buildDev.properties
for development environment, similarly buildTest.properties
and buildProd.properties
for test and prod environment.
Note: git rm --cached
is used when you have pushed a file to remove which you shouldn't have and now also want to untrack it. You can add the file name in .gitignore
in this case and then use git rm --cached
to delete it from staging area and then commit. Now this commit removes the file which can be pushed to master without removing the file locally.
Upvotes: 0
Reputation: 1940
I understand what your trying to do and the reasons behind it are valid ones. But the thing is, it contradicts the distributed and parallel nature of Git. Git is designed to be a:
Version-control system for tracking changes in computer files and coordinating work on those files among multiple people
If your file is being taken care by Git, it assumes the file may be changed and needs to be tracked (otherwise why bother with a version-control system). As you pointed out, it is possible to do it locally because it is one isolated decision to tell Git that in your own machine that you do not want to commit changes to that file. Trying to do it globally is basically like trying to use Git as a simple file storage system.
Therefore, keeping in mind that Git is not designed to do what you want, you might want to consider a few options:
git update-index --skip-worktree <file>
(you can read more about why use instead of other options here);Upvotes: 2