GIT and clicking with ignored files

What is the procedure you should follow using git? I will give my procedure (which, somehow, does not work 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 I click on the remote, the settings files on the remote control are deleted, due to which my test environment dies. I just want the settings files to be ignored if I click and do not delete.

What have I done wrong / forgot? Any ideas?

+4
source share
3 answers

from what I understand, the settings file was already tracked in the git repository that you cloned. this means that even if you add it to .gitignore , it will still be tracked.

to delete a file from history, and make sure that it is ignored in the future, you must

  • add it to .gitignore (as you already did)
  • run git filter-branch --index-filter 'git rm --cached --ignore-unmatch settingsfile' HEAD

note that you need to execute the above command for each branch where the file is located.

then you need git push -f origin master (if master is the name of the branch and origin is the name of the remote)

You can refer to this guide for more information.

In addition, as Rafid K. Abdullah said, you did not delete anything (if you followed the workflow that you describe in your message); You have just added modifications that you can easily return. what for git for everyone :)

+3
source

I understand that the settings file you are talking about is your settings, not the .git folder. If I understood correctly, then this does not always work to add them to .gitignore, because all that .gitignore does is that it does not check these files locally when you use 'git commit -a', 'git diff ', etc., but if you already have them in your local repository, they will still be transferred to the remote server.

Having said that, I don’t think you lost your settings file on the remote server, because all you did was add more commits, so you should find the settings file in the history.

In any case, unfortunately, unlike SVN, if you just learn a few steps on using GIT, you will always be mistaken. At first I made a lot of mistakes, then admitted that I need to read a book about this. But at first I wanted to understand its concepts, because this is what sometimes causes problems (for example, what is the difference between “master of origin” and “source / master”, etc.), so I found this very useful page, and I recommend read it to you:

http://www.eecs.harvard.edu/~cduan/technical/git/

And I also found this very interesting book:

http://progit.org/book/

You do not need to read all this, just read the basics and, most importantly, branching.

Hope this helps.

+2
source

Do not add the settings file to the .gitignore file, instead save your changes to the settings file with git stash , click and drag as usual. When done, restore the settings file using git stash apply .

0
source

Source: https://habr.com/ru/post/1334478/


All Articles