0

I understand that "commit" is sort of like "updating" the "local repo" and "pushing" copies the local repo changes over to the remote / online repo, right?

But if I am modifying my code locally (e.g. my repo is located in my documents, where my code is, and this is where I make my edits), isn't that already "changing my local repo"? Why do I have to commit?

MyNameIsKhan
  • 2,594
  • 8
  • 36
  • 56

1 Answers1

4

When you modify your code, you are creating changes to a text file. The text file has non memory of when and how you made your changes, it always reflects the latest version.

When you tell git that you want to commit changes, git analyses the differences between the text file now and when you made the last commit. It stores these changes in a highly compressed way. i.e. It does't store the whole file.

You can now make more changes and commit again, again, git will store the differences or 'deltas' between the last commit and the current state of the file.

in this way you can roll back the file to the state at any commit simply by undoing the stack of commits.

Dave Durbin
  • 3,562
  • 23
  • 33
  • 1
    So it the "local repo" some compressed, esoteric file located somewhere that isn't my working code folder? How many commits does it remember? – MyNameIsKhan May 06 '15 at 01:09
  • 2
    Yes. The local repo is usually located in a .git sub-directory of each directory in your source tree. The leading '.' makes the directory hidden. Git will remember all commits from the point at which you create the repo. It can also remember commits across multiple branches. A good resource for this info is http://git-scm.com/book/en/v2/Git-Basics-Getting-a-Git-Repository – Dave Durbin May 06 '15 at 01:13