2

To satisfy github 100Mb requirement, I run the following to ignore some large files:

$ find ./* -size +100M | cat >> .gitignore

but when I run add * later, it is still adding the >100MB file to commit.

$ git add *
warning: LF will be replaced by CRLF in hw1/input/act_test.csv.
The file will have its original line endings in your working directory

How can I make this gitignore work? Thanks in advance for ideas and advices.

add: my intent is to make add * not track the large csv file any more, following answer does not seem to work.

Pythoner
  • 5,265
  • 5
  • 33
  • 49
  • 1
    Are you sure you want to use `./*` instead of `.`? That'll add everything except what's in the root folder. – Mad Physicist Nov 29 '18 at 04:23
  • Also, have some of these files already been committed? If so, you will need to purge them. You can't alter past history with just ignore and commit. – Mad Physicist Nov 29 '18 at 04:25
  • 1
    Possible duplicate of [How to make Git "forget" about a file that was tracked but is now in .gitignore?](https://stackoverflow.com/questions/1274057/how-to-make-git-forget-about-a-file-that-was-tracked-but-is-now-in-gitignore) – phd Nov 29 '18 at 07:37
  • https://stackoverflow.com/questions/2100907/how-to-remove-delete-a-large-file-from-commit-history-in-git-repository – phd Nov 29 '18 at 07:38
  • @MadPhysicist, yes, I used add * to keep my project updated, then I can access it anywhere, I am the main contributor, so call `add *` often to keep it updated. – Pythoner Nov 30 '18 at 01:40

2 Answers2

3

Previously added files are not affected by, adding them later to gitignore. Take a backup of the files and delete the files locally and commit them. So, that they are not tracked by git. Now, Paste back the files to the original place and you can add the bigger filenames to gitignore. Now, git will not be tracking them, as they are considered fresh files.

Another way is to use, as suggested by @alfunx, git rm --cached <file>. The file will be removed from cache(index) and once you commit, the file will not be tracked anymore. You can also update .gitignore accordingly to avoid any further tracking of the file.

Read more about it in gitignore documentation

A gitignore file specifies intentionally untracked files that Git should ignore. Files already tracked by Git are not affected; see the NOTES below for details.

[...]

NOTES

The purpose of gitignore files is to ensure that certain files not tracked by Git remain untracked.

To stop tracking a file that is currently tracked, use git rm --cached.

Venkataraman R
  • 12,181
  • 2
  • 31
  • 58
  • Thanks for your answer, but my intent is to make add * not track the large csv file any more, this does not seem to work, when I call `add *`, it adds back the large file again. – Pythoner Nov 30 '18 at 01:39
  • 1
    Your shell expands `*` to a list of every file in the directory, so Git sees every file listed explicitly. If you want git to check the directory contents for ignore processing, feed it the directory, use `git add .` (a dot). edit: ignore processing is to stop git auto-adding files, not to stop you adding them explicitly. – jthill Nov 30 '18 at 01:51
0

Rather than ignore the file (often I will add it back by calling add . method in later time), there is a better way to resolve the issue, git lfs, see my usage below, this will help to push the large files to github.

 $git lfs install
 $git lfs track "*.csv"
 $git add .gitattributes
 $git add act_train.csv
 $git commit -m "test lfs"
 $git push

Done

Pythoner
  • 5,265
  • 5
  • 33
  • 49