0

Unfortunately, my .gitignore file or certain commands in it get completely ignored.

When I check out a branch or from remote or pull/fetch, the .vscode folder is always removed, so that all my tasks get lost and I have to create .vscode folder with the tasks.json file inside again and again manually.

How can I fix the problem without overwriting or deleting my current branches? If these (currently 3 branches) are deleted, the consequences would be really bad.

This is my current .gitignore file. For the folder .vscode I have already tried different approaches and, for example, removed the lines with the exclamation marks, etc. Still does not work.

My .gitignore file ist placed in the root folder of an angular 7 project and I'm using visual studio code.

# See http://help.github.com/ignore-files/ for more about ignoring files.

# compiled output
/dist
/tmp
/out-tsc

# dependencies
/node_modules

# IDEs and editors
/.idea
.project
.classpath
.c9/
*.launch
*.iml
.settings/

# misc
/.sass-cache
/connect.lock
/coverage
npm-debug.log
testem.log
/typings

# e2e
/e2e/*.js
/e2e/*.map

# System Files
.DS_Store
Thumbs.db

.vscode/*
!.vscode/settings.json
!.vscode/tasks.json
!.vscode/launch.json
!.vscode/extensions.json
Codehan25
  • 2,704
  • 10
  • 47
  • 94
  • What is your final purpose? Leave a `.vscode/tasks.json` there with Git? – Geno Chen Mar 05 '19 at 17:24
  • 1
    I think you are jumping between branches/revisions where some of them have that directory tracked and others don't.... so, if you are on a revision where the directory is tracked... and you move to a revision where it isn't... what should git do? It will delete it, of course. i guess you would need to rewrite the history of the project to not have the directory tracked so that this doesn't happen. – eftshift0 Mar 05 '19 at 17:25
  • Or, ignore all files in `.vscode` but left `.vscode/tasks.json` tracked in Git? – Geno Chen Mar 05 '19 at 17:25
  • The .vscode folder should be ignored completely, no matter if I push, pull, fetch something or switch between branches while I code different stuff. The .vscode folder is only for the configuration of my IDE and should not be included in the versioning. – Codehan25 Mar 05 '19 at 17:27
  • @eftshift0 How can I rewrite the history without deleting or loosing my current branches? I've never done this before. As I said, the .vscode folder and everthing inside it should be ignored completely. – Codehan25 Mar 05 '19 at 17:31
  • @Codehan25 You may use `git filter-branch` to rewrite your history. But I am not sure how this command fits you. Upvoted @eftshift0 's comment. – Geno Chen Mar 05 '19 at 17:34
  • @GenoChen Hmm, I'm just too risky right now. Like I said, I've never done anything like that. – Codehan25 Mar 05 '19 at 17:40
  • The problem is also that in the current state changes in my tasks.json within the .vscode folder are still being tracked, although within the .gitignore it is defined that this should not happen. As soon as I make a change in my tasks.json, the file will be displayed with git status. – Codehan25 Mar 05 '19 at 17:48
  • Ok... there's a misunderstanding there. Adding a file that is already tracked to .gitignore makes no difference. .gitignore works for files that are not tracked. – eftshift0 Mar 05 '19 at 18:26
  • I don‘t added the file myself. It is a remote repo and I used git pull to pull it to my local environment. After that I just fetched remote branches and linked them with my local branches with the same name. So I never touched the .gitignore file, in which the .vscode folder was allready added a long time ago before I was in the Company. So what should I do now? – Codehan25 Mar 05 '19 at 19:38
  • Note: I'm **not** responsible for any side-effects caused by the answer(s) of the above-linked question. (It might be a good idea to discuss this with your coworkers before proceeding.) – SamB Apr 26 '19 at 01:50

0 Answers0