0% found this document useful (0 votes)
31 views

9/16 L&L, "Git" by Francois

The programmer meets Master Git, who teaches them that git checkout can be used to change branches, create branches, and update single files without changing branches. The programmer realizes git checkout has multiple uses. The document then provides an overview of the anatomy of a git repository, including references, snapshots organized by time in a content-addressable filesystem, and snapshot file hierarchies. It discusses concepts like branches and tags being pointers, versions being stored regardless of commits/branches, and losing only uncommitted work. Tips are provided for inspecting the commit tree, using time travel, the reflog, and bisecting commits.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
31 views

9/16 L&L, "Git" by Francois

The programmer meets Master Git, who teaches them that git checkout can be used to change branches, create branches, and update single files without changing branches. The programmer realizes git checkout has multiple uses. The document then provides an overview of the anatomy of a git repository, including references, snapshots organized by time in a content-addressable filesystem, and snapshot file hierarchies. It discusses concepts like branches and tags being pointers, versions being stored regardless of commits/branches, and losing only uncommitted work. Tips are provided for inspecting the commit tree, using time travel, the reflog, and bisecting commits.
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 17

9/16 L&L, git

by francois

A UNIX programmer was working in the cubicle farms. As she


saw Master Git traveling down the path, she ran tomeethim.
- It is an honor to meet you, Master Git! she said.
I have been studying the UNIX way of designing programs
that each do one thing well. Surely I can learn muchfromyou.
- Surely, repliedMasterGit.
- How should I change to a different branch?
askedtheprogrammer.
- Use git checkout.
- And how should I createabranch?
- Use git checkout.
- And how should I update the contents of a single file in my
working directory, without involving branchesatall?
- Use git checkout.
After this third answer, the programmerwasenlightened.

Anatomy of a git repo


References (pointers)

2nd level tree: snapshots ordered by time

1st level tree: snapshot file hierarchy

Content Addressable Filesystem

Content Addressable FS
SHA1

Filename

Source

objects dir
ZIP(1)

Contents

(1) Some files are saved as a pointer to a base file, and a file
delta to save space

Snapshot File Hierarchy

Note: Trees are saved as files in the Content Addressable FS

Snapshots ordered by time

References

Why is this important?


Some things become easier once you understand
them:
Branches & Tags are just pointers, moving them
doesnt affect the commit tree
You cannot destroy a commit, only misplace it
All versions of the file are stored in the filesystem,
regardless of commits & branches

Stage & Working Dir

Think of the stage as a floating commit


The only thing you can lose is what is in your WD

What does commit do?

What does checkout do?

What does reset do?

Inspecting the commit tree


Q: Whats in my tree?
A: $ git log --graph --oneline --decorate
Q: What commits dont come from merges?
A: $ git log --no-merges --oneline
Q: What commits are on the release branch but not master?
A: $ git log master..release-3.5 online
or
$git log release-3.5 --not master --oneline
Q: How do master & branch differ?
A: $ git log --left-right master...release-3.5 --oneline

Time Travel
$ git checkout @{10 minutes ago}

$ git show master @{one.month.ago}

$ git diff @{yesterday}

$ git whatchanged --since="2 weeks ago"

The RefLog

Bisect
$ git checkout <known-bad-commit>
$ git bisect start
$ git bisect bad
$ git bisect good <known-good-commit>
git selects the next commit to test
test the commit
$ git bisect <good or bad>

Share some tips & tricks


https://pebbletechnology.atlassian.net/wiki/pages/
viewpage.action?pageId=44925274

You might also like