0

I initialized a folder with git init. The size of contents in that is around 600MB. After doing git add, The size of .git became 600MB, So, It literally stores all the contents of my files? I thought git add just considers the files as to be tracked, But If that is true, The size shouldn't be that large, Right? Correct Me, If I am wrong.

If yes, can you suggest something more simple for tracking my changes locally?

Update: Even with git gc, Size didn't change much Actually My requirement is, I am storing Videos, Text Files, Pdf Files etc... And I keep changing them, So, I want to go back sometimes. Due to large size of Videos, It is increasingly bloated.

I think there is no other choice other that git. Thanks Guys

Appaji Chintimi
  • 613
  • 2
  • 7
  • 19
  • 2
    It iterates the added files. Each file's content is stored as a blob object in `.git`. If multiple files have the same content, only one corresponding blob is created. Basically, all the contents are stored. They could be loose objects at first. After `git gc`, they can be compressed as packed objects which could be smaller. – ElpieKay Sep 16 '20 at 06:19

3 Answers3

3

git add both marks the file as tracked, and copies it to the staging area. Copying to the staging area before you commit allows one to build up a commit in pieces, particularly useful with git add -p and git add -i.

You can use git add --intent-to-add to only track the file, but eventually you will need to add and commit it.

The good news is Git will compress those files, so after committing them and running git gc they should be substantially smaller, assuming they're compressible.

If you commit changes to large files, particularly large binary files, your repository will get very large. Instead use Git Large File Storage to store the history of the large files in the cloud.

Schwern
  • 153,029
  • 25
  • 195
  • 336
3

The git add command adds a change in the working directory to the staging area. It tells Git that you want to include updates to a particular file in the next commit. However, git add doesn't really affect the repository in any significant way — changes are not actually recorded until you run git commit.

You can use a .gitignore file to remove unwanted files that we can generate or download Ex: dll, node_modules.

This link shows you how to add a .gitignore file to your repository

Rahul Bhobe
  • 4,165
  • 4
  • 17
  • 32
Dilanka Bc
  • 31
  • 4
2

.git folder tracks all versions of the tracked files. git add will mark changes (by copying them to a staging area), then git commit will record them in the repository. Yes, it literally stores all the contents of your files; not only that, but all versions of the contents. Otherwise it would not be much of a version tracker - without recording the contents in a separate location, the only way I can think of to go back to an earlier version of a file would be a time-travel machine, and git doesn't implement one yet. :)

That said, git was developed to track source files, and it is very unlikely you have 600MB of source files. You should avoid adding data files, or files that are products of your code or the compilation process (and, for a different reason, any configuration files that can differ per developer). To help with this, one of the first things you should do in a repository is to craft a .gitignore file, and check with git status whether any files you would not want to commit are considered by git.

Amadan
  • 191,408
  • 23
  • 240
  • 301