Reputation: 11098
I want git
to ignore application.ini
, so I've added .gitignore
/application/configs/application.ini
The problem is that I didn't commit the .gitgignore
before everything else, I committed it afterwards. So I read here: Github gitignore help that you can use:
git rm --cached application.ini
After the fact.
So I commited the change along with all the other members of the team, it showed that application.ini
was deleted and pushed to repo. After pulling, the application.ini
file was removed.
So I realised that git is not tracking so we should add out own applciation.ini
and all configuration will stay locally and won't get commited.
The problem is that when I checked out a commit from a while back, and then went back to master: application.ini
was removed again.
Maybe I am doing something wrong, or just not overstanding the concepts/
Upvotes: 0
Views: 192
Reputation: 12541
As already answered the problem is that the deletion of the file is a commit, so it would be applied when you switch between checkouts.
The commit deletes the file named application.ini
so a naive solution would be to rename the file and add the new renamed file to .gitignore
.
Another solution is to completely remove the references of application.ini
from the repo history.
This procedure will let you amend
the first commit and add the .gitignore
, and then rewrite all the git history. You can find the procedure on the accepted answer to this question Git ignore & changing the past.
Upvotes: 1
Reputation: 387825
The problem is that you committed the removal of the file. As such, when you switch from a revision which tracks the file to a revision which does not track the file, Git will perform this removal and you end up without the file.
In the reverse when you switch from a revision which does not track the file to a revision which does, Git will add the file from that revision†. And if you get back, it will be removed again.
So if you want to keep the file untracked, while still working with old revisions, you have to restore the file yourself unfortunately.
Btw. the usual approach to such configuration files is to track some application.example.ini
file which shows example configuration but is not used. The user then can copy that and rename the copy to application.ini
to have a local configuration which is not part of the repository. Or you have a default configuration file and additionally an (untracked) user configuration (both which are actually loaded in the application), e.g. application.user.ini
.
† Note that Git will actually only let you switch to a revision which adds the file, if the file does not currently exist or if the contents are identical to those of the target revision. Otherwise you could lose data, so Git will not let you do that.
Upvotes: 1