7

I am using Visual Studio 2013 and GitHub for my source control, and a problem I keep having is that it keeps trying to commit all of the .js files that are generated from .ts (Typescript) files.

The reason this is bad is because I've had experiences where committing these causes building to fail, and only closing and re-opening Visual Studio fixes the issues.

My knowledge of git is still rudimentary in general, but it seems to me this must be a common problem. I do not want to just exclude all .js files because there are many that are not generated from typescript; So is there anything I can do about this other than MANUALLY excluding the files every single time I do a commit?

Ciel
  • 4,290
  • 8
  • 51
  • 110
  • Are the JavaScript files you wish to exclude contained in separate directories from the ones you wish to commit? – ChrisGPT was on strike May 05 '14 at 12:08
  • Yes. All of the typescript files in the entire project are underneath a single place, any non-typescript javascript files go somewhere else. – Ciel May 05 '14 at 12:42

2 Answers2

8

Add some file patterns to one of Git's ignore files.

  • The .gitignore file is usually committed with the repository, so its ignores are shared by all users.
  • The .git/info/exclude file is not committed with the repository, so it can be used for your own personal ignores.

To ignore all .js file in a directory foo, use something like this:

foo/*.js

Note that patterns in the ignore files only prevent files from being tracked. This means that if you have already committed a file, it will continue to be tracked. Modifications will cause the file to show up in your "uncommitted changes", and something like git commit -a will cause changes to be committed.

If you have a committed file that you wish to ignore going forward, you will have to remove it from the repository. This is a frequent question on SO, and there are many questions about handling this.

It is worthwhile to read up on Git's ignore feature, as it has a few gotchas.

Community
  • 1
  • 1
ChrisGPT was on strike
  • 127,765
  • 105
  • 273
  • 257
  • Hrnn. This doesn't seem to work. I used `*scripts/home/*.js`, and it is still trying to commit `js` files that are in that folder, or a folder inside of it. – Ciel May 05 '14 at 15:35
  • This is my `.gitignore` file, http://pastie.org/pastes/9142933/text?key=dzvlemds4joimfo4ysalq - and the file it is trying to commit is `app_content/scripts/home/app/init.js`. – Ciel May 05 '14 at 15:38
  • 1
    @Ciel, you've found one of the gotchas :-). Try using `scripts/home/**/*.js`. As explained in the manpage link above, "A slash followed by two consecutive asterisks then a slash matches zero or more directories. For example, `a/**/b` matches `a/b`, `a/x/b`, `a/x/y/b` and so on." You may need the leading `*/` that is in your current pattern, but I don't think so. – ChrisGPT was on strike May 05 '14 at 17:21
  • Yes, that does seem to have fixed it. Thank you. – Ciel May 06 '14 at 16:57
  • Yay! This is so totally awesome! I have been able to make all kinds of cool flexations to this to make it work exactly how I want! Thank you so much again!!! – Ciel May 15 '14 at 15:23
3

There is this feature request : http://github.com/TypeStrong/atom-typescript/issues/253

For now, I used

  • rename file, ex, myfile.ts.ts
  • include in .gitignore my auto-generated typescript *.ts.js and *.ts.js.map
Wagner Pereira
  • 1,050
  • 11
  • 11