2

I am using VS code with git. There are a lot of files(4G+) in the repos and I don't care about most of them. But they are needed during compile. So when I create the VS code workspace, I only added the folder/files I am interested. Then I found the source control in VS code listed 5K files and complained they are modified but actually not. I think the reason is these files are tracked by git but I didn't add them to my workspace. Is there a way to ignore such files?

.gitignore doesn't work for this because all the files are not local, they are all tracked by git. I don't want to add them all to the VS code workspace since I only care about part of them.

Thanks in advance!

Kejia Cui
  • 111
  • 1
  • 5
  • You mean the .gitignore file? https://help.github.com/articles/ignoring-files/ – ggdx Nov 27 '18 at 11:29
  • Duplicate: https://stackoverflow.com/questions/8527597/how-do-i-ignore-files-in-a-directory-in-git – ggdx Nov 27 '18 at 11:32
  • Actually not. I think .gitignore only works for the untracked files. But in my case, these files are all tracked by git. – Kejia Cui Nov 27 '18 at 11:55
  • What you want is `git --assume-unchanged`: https://git-scm.com/docs/git-update-index – ChatterOne Nov 27 '18 at 13:30
  • @ChatterOne No, this is `skip-worktree`. `assume-unchanged` is only to improve perf of `git status` (and perhaps other git commands) – Philippe Nov 27 '18 at 15:57
  • @Keija-Cui "Then I found the source control in VS code listed 5K files and complained they are modified but actually not". You've got a problem here. If they are not, git must not show them as changed. You'd better find why git think they are and solve this problem instead of trying to ignore them – Philippe Nov 27 '18 at 16:04
  • @Philippe I'm not sure what you mean? I use `--assume-unchanged` on files and the effect is that if I change those files, they're not included in the detected changes when you do a commit. Maybe this is just a side effect, but it's how I make git skip files that are already in the repository and I don't want to push (e.g. configurations local to my dev machine). – ChatterOne Nov 28 '18 at 07:42
  • @ChatterOne https://stackoverflow.com/a/13631525/717372 – Philippe Nov 28 '18 at 08:34

1 Answers1

3

If you want to untrack files that have already been added to a (cloned) git repository (I think that is what you mean), you can use git rm --cached filename

You can also tell git you want your own independent version of the file or folder. For instance, you don't want to overwrite (or delete) production/staging config files. The way to do this is by using git update-index --skip-worktree <path-name>.

For a more elaborate discussion on this topic please check our This question and This link

Psychotechnopath
  • 2,471
  • 5
  • 26
  • 47
  • Thanks for your reply! I have tried .gitignore. But my understanding is, it can only ignore the untracked files. But in my case, all the files are in the repos, they are not generated during compile. – Kejia Cui Nov 27 '18 at 11:52
  • I need some clarification; the repo you are talking about, did you clone it into VS with git? Or did you simply download the files you wanted and set them up in your VS code workspace? – Psychotechnopath Nov 27 '18 at 11:58
  • I cloned the repo(using git command not VS). Then I added some sub-folder to VS code and created a workspace. So not all files are involved in the workspace. And VS code complains there are changes for these files(tracked by git but not added to VS code workspace). – Kejia Cui Nov 27 '18 at 12:04