Reputation: 8046
What is the exact the procedure you have to follow using git? I will give my procedure (which is, somehow, not working very smoothly):
- cloned a repository: (works fine)
- added settings files to .gitignore to prevent overwriting the originial
settingfiles on the remote (= test environment)
- made changes to my local repository and committed it locally (works fine)
- pushed it from local to remote (did not work properly)
When pushing to the remote the settingfiles on the remote are deleted, which caused my test envirnment to die. I just want the settings files to be ignored if I push and not deleted.
What did I do wrong/forget? Any ideas?
Upvotes: 4
Views: 11743
Reputation: 3880
from what i understand, the settingsfile was already tracked in the git repo that you cloned. this means that even if you add it to .gitignore
, it will still be tracked.
to remove the file from the history, and make sure it's ignored in the future you should
.gitignore
(as you already did)git filter-branch --index-filter 'git rm --cached --ignore-unmatch settingsfile' HEAD
note that you need to run the above command for each of the branches where the file is present.
then you need to git push -f origin master
(if master
is the name of the branch, and origin
the name of the remote)
you can refer to this guide for additional info.
Also, as Rafid K. Abdullah said, you haven't deleted anything (if you have followed the workflow you describe in your post); you have just added modifications that you can easily revert. that's what git is for after all :)
Upvotes: 3
Reputation: 20179
I understand that the settings file you are talking about is your settings rather than the .git folder. If I understood correctly, then it doesn't always work to add them to .gitignore, because all what .gitignore does is that it doesn't check for these files locally when you use 'git commit -a', 'git diff', etc., but if you already have them on your local repository, then they will be pushed to the remote server anyway.
Having said that, I don't think you lost your settings file on the remote server, because all you did is adding more commits, so you must find the settings file in the history.
Anyway, unfortunately, unlike SVN, if you just learn few steps to use GIT, you will always make mistakes. I did MANY mistakes at the beginning, then admitted that I have to read a book about it. But first, wanted to understand its concepts because this is what makes troubles sometimes (e.g. what is the difference between 'origin master' and 'origin/master', and so on.), so I found this very useful page and I recommend you read it:
http://www.eecs.harvard.edu/~cduan/technical/git/
And I also found this very interesting book:
You don't have to read it all, just read the basics and -most importantly- branching.
Hope that helps.
Upvotes: 2
Reputation: 47572
Don't add settings file to to the .gitignore
file, instead save your changes to settings file with git stash
do push & pull as usual. When done, restore your settings file with git stash apply
.
Upvotes: 0