[kwlug-disc] How git works

Chris Frey cdfrey at foursquare.net
Mon Apr 21 21:44:06 EDT 2014


On Wed, Apr 16, 2014 at 10:16:05PM -0400, John Johnson wrote:
> I can understand the 'view' of the files as given through the Git
> bash window. But I am not clear as to how Windows apps, e.g. a text
> editor, and XAMPP find the files associated with the branch
> currently active in he Git bash window.
> 
> What happens if I have modified a file in one of the branches?
> Say it is a file accessible through FF with
> /localhost/projectName/indexTest.php

There is nothing magical about the files in your git bash window.
You can navigate to them in Windows with the file explorer or a
browser.  They are all regular files.

Git's "brains" are kept in the .git/ directory in your root folder
of your project.  This is where copies of every file you've ever
committed, and every revision of those files you've ever committed,
are stored.  They are stored as compressed blobs, with a filename
based on their contents: a SHA1 sum.

When you checkout a branch, git looks in .git/ and finds all the files
pertaining to that branch.  It then expands and copies every file
into your working tree, and removes files that were in the old branch
but not in the new one.  Any changes you make to those files will be
different from what git knows to be the "content" of that branch.
In other words, the SHA1 sum of one or more files will be different.
Those are the files you need to commit, creating a new commit on your
branch.

If you're looking at the git-cat-file command mentioned earlier,
you'll notice it asks for a blob, tree, commit, or tag.  These are
the building blocks of git.

	A blob is compressed file content with a SHA1 filename.
	A tree is a list of files and other trees, stored similarly
		to a blob, having a SHA1 filename.
	A commit is a list of parent commit(s), author, tree, and
		a description, also stored with a SHA1 filename.
	A tag lists a given commit, and a description, and an optional
		cryptographic signature, stored again with a SHA1 filename.

As you can see, if you have a signed tag, you can verify everything else
through the chain of SHA1 sums.

These SHA1 sums are what you see all over the place in git.  And you
can use them to reference individual pieces of data as needed.


For example, you can do:

	git cat-file -p master^{commit}

And you'll see the contents of the latest commit on the master branch,
including a tree SHA1 and a parent commit SHA1.  You can then view this
tree with:

	git cat-file -p master^{tree}

which is the same output as

	git ls-tree master

And you can pick out one of the SHA1's of one of the files in the list
and see it too:

	git cat-file -p <SHA1sum-goes-here>
or
	git cat-file blob <SHA1sum-goes-here>

And you can recursively view the trees, using their SHA1's.


But the files in the working area, which you are editing, and seeing in the
git bash window, are just plain old fashioned files.  Git stores the
copies of them in its own storage area.  As long as you don't delete
the .git/ directory, all your content is safe, no matter what you do
with the visible files themselves.

- Chris






More information about the kwlug-disc mailing list