Git is a free and open source distributed version control system designed to handle everything from small to very large projects with speed and efficiency.
rsync -av --delete $SRC $DEST
rdiff-backup
Hey, we are hackers after all :-)
d22f6ac
$ git log -1 commit d22f6ac868fd62dba328b555d93ec63b0fb00194 Author: Harald Schilly <harald.schilly@gmail.com> Date: Sat Oct 6 21:07:48 2012 +0200 fragment: zoom and relative offset animation
$ cat .git/HEAD ref: refs/heads/master
$ cat .git/HEAD b1b7e86e011aebad8df6d9af33214abedb113983
HEAD
is where you are8frfa1
master~
or master~2
...8r7af^2
master~3^2~~
master..topic1
master...topic2
sudo apt-get install git
* MacPorts: sudo port install git-core
### Install Tools
sudo apt-get install gitk git-cola
git
.
git help [<command>]
git [<command>] --help
~/.gitconfig
and project specific local
.git/config
configuration file.
Edit them either directly (leet!) or via
git config [--global] [--edit] ...
$ git config --global user.name "Gitti Gitian"
$ git config --global user.email "gitti@gitiscool.com"
# and check it
$ git config --global user.name
Gitti Gitian
$ git config --global alias.[SHORTCUT] [COMMAND ...]
$ git aliases st = status ci = commit ll = log --oneline --graph --decorate -25 lla = log --oneline --graph --decorate --all -25 br = branch co = checkout df = diff who = shortlog -s -- aliases = !git config --get-regexp 'alias.*' | colrm 1 6 | sed 's/[ ]/ = /'
$ git config --global core.editor "vim"
git mergetool
,
when it gives up resolving conflicts.
$ git config --global merge.tool "meld"
$ git config --global color.ui true
$ git config --global core.excludesfile ~/.gitignoreand project specific:
$PROJ_ROOT/.gitignore
~/.gitignore
:
*.o *.so *.class *.pyc *~ # temporary editor files *.swp # vim temp file *.min.js *.log *.DS_Store # Mac users
$ mkdir myshinynewrepo $ cd !$ $ git init
$ git clone [git|http]://server/.../project.gitThen, this remote server is already setup for sending your commits to it ("pushing").
status
command.
Its output also lists useful commands, which will be explained in the next slides.
$ git add fileA fileB ... # or just all, which are already tracked or deleted $ git add -A # or just a part $ git add -p fileX # to get rid of files $ git rm fileY
git status
.
git commit
Additionally, your author information, the time and a custom
"*commit message*" are stored.
$ git diff HEAD~3..HEAD~2 index.html diff --git a/index.html b/index.html index 43063fb..06d9a2e 100644 --- a/index.html +++ b/index.html @@ -140,7 +144,9 @@ Gitti Gitian - <code>--global</code> sets this for your entire account! + <aside class="footnote"> + Remember: <code>--global</code> sets this for your entire account! + </aside> </section>
-
= removed +
= added
$ git commit -am "commit message"
git log
.
* -[number]
limits to the last [number] entries
* --oneline
self explanatory
* --graph
tries to be artsy
* --decorate
shows HEAD, branches, and tags
$ git log -5 --oneline --graph --decorate HEAD~59 * c411c4d Merge pull request #131 from Sinetheta/master |\ | * 495cb98 changed theme file swap to be relative to theme file instead of slide-deck |/ * aa97d80 correction to code style in sky theme, adjusted transition demo page * 0c06469 prevent same theme from loading repeatedly * dc9b93a tweaks to the simple theme * 90f343e add theme config option, add sky theme, fix line-height of <small> * e3f3e9d Update README.md * 141d694 support for named links (closes #55)
git branch branch_name [commit] [-f]This creates a new branch right where the HEAD is, or at the given commit.
-f
can be used to move an existing branch *reference* around.
-d
deletes and -m
renames.
checkout
command has several basic functions.
The most basic one is for switching branches,
which moves the HEAD and populates the index and working directory:
git checkout branch_nameCopy a file from the repository:
git checkout [commit] -- path/filename
reset
sounds a bit more scary - and yes it is.
It's job is to move around the branch reference underneath the HEAD.
--soft
only moves HEAD (like all modes do) and doesn't touch index
--mixed
(default), resets index
--hard
resets index and working directory (local changes lost forever!)
checkout
, reset
also
has a mode where it works on paths to files.
This resets the entries for the specified files in the index.
git reset [commit] -- path/filenameHence, this is the opposite of
add
.
merge
command has the job, of creating
a new commit with more than one parent.1
Assume the following history exists and the current branch is "master": A---B---C topic / D---E---F---G master Then "git merge topic" will replay the changes made on the topic branch [...] and record the result in a new commit [...] A---B---C topic / \ D---E---F---G---H master
Well, 99% happens locally.
The missing piece is a way to send and recieve commits
as part of branches, based on given references.
sshd
server and Git installedgit init --bare
usually ending in *.git
.bundle
for the paranoid on an isolated machine :-)git remote
manages all remote servers.
git remote add [name] [URL]
adds a remote server.
And you can list remotes
$ git remote -v show origin git@github.com:.../...git (fetch) origin git@github.com:.../...git (push) uni ssh://name@login/.../repo (fetch) uni ssh://name@login/.../repo (push)
git clone git://.../
,
Git has already set you up with a "*remote*"
called **origin** pointing to the given URL.
Also, your main branch is usually called **master**.
Hence, the reference to the master branch on the server is origin/master
.
(But you can call them as you like.)
push
uploads commits that aren't on the server to it
* fetch
downloads new commits which you don't have
* pull
does a fetch and also merges with your respective branch
git branch --set-upstream master origin/masterAlso, when pushing to a remote, you can do this via the
-u
switch: git push -u joe featureX
.
$ git branch -vv * master cf36560 [origin/master] readme other d39c6f1 [origin/other] init "other" branch, ...
git remote update
to get the references straight.
Then, e.g. git log --decorate
shows the remote references
at the correct positions!
git tag name [commit]
creates a named reference to a specific commit.
They are very similar to a branch reference, but stay fixed.
Usually, it is used to name a specific release version, v2.7.1
.
Checking out a tag brings you into the
detached HEAD state.
It's also possible to cryptographically sign it.
git reset [--hard] HEAD^
git reflog
lists you the relevant hashes.
Use reset --hard
to reset everything back to how it was.
Note: This reflog is only local to your repository!
$ git ls-tree HEAD 100644 blob aa5fa7141766f8cf11d1d25d39cd04a2ffee7a95 .gitignore 100644 blob e69de29bb2d1d6434b8b29ae775ad8c2e48c5391 .nojekyll 100644 blob 6fed1c32d012538ea783b0eb8d13a643cc981666 LICENSE 100644 blob 27ed242ad6ab8bbb19c9b6182ee47b3939a15db0 README.md 040000 tree 96d0c04c1d308c31faacfa26eeee2b4b256be116 css 100644 blob a9aa16404dd4d78493208929095137097f133975 index.html 040000 tree dd1ae6043bf368f504b2aff6e3b936607bf0be07 js 040000 tree 6e46172d37ce36c570fd65458eefc02cee58c8b2 lib 100644 blob 86578fe468e926513e2ca87d4c5792e333b4b58d package.json 040000 tree 04016b53decd21110649ef3cfdc936ca7849ddce plugin 040000 tree 3f2ac677462a553dbcfe81088d8b276b52c50f29 res
$ git show 27ed242ad6ab8bbb19c9b6182ee47b3939a15db0 # YAGT - Yet another Git talk This is a fork of [reveal.js](https://github.com/hakimel/reveal.js) with the goal to build a talk about [Git](http://www.git-scm.org/) and hence explaining it. [...]
$ git show eec35ee commit eec35ee92b9e3d1f97aecd49b6d884db82604c47 Author: Harald Schilly <harald.schilly@gmail.com> Date: Sun Oct 7 01:19:58 2012 +0200 more links diff --git a/index.html b/index.html index 97f4792..1744916 100644 --- a/index.html +++ b/index.html @@ -502,21 +502,33 @@ It is possible to *skip* the staging area. *Both are modified!* [...]
$ git checkout -b fix666 [start_point] $ git cherry-pick 5d3e1b6 Finished one cherry-pick. [master e458a9b] Bug fix for Issue #666 3 files changed, 36 insertions(+), 3 deletions(-)Note: Later, merging branches containing the same commits are no problem, since they produce the same content!
$ git checkout side-branch $ git rebase master First, rewinding head to replay your work on top of it... Applying: ...
git rebase -i HEAD~[n]
It lets you:
git rebase -i HEAD~[n]
or
git checkout END_SHA1 git reset --soft START_SHA1 git commit --amend -m "squashed history" TARGET=`git rev-list HEAD --max-count=1` git checkout master git rebase --onto $TARGET START_SHA1[credits for this madness](http://stackoverflow.com/questions/598672/git-how-to-squash-the-first-two-commits)
Talk |
Git |
Resources |
Based on work by Hakim El Hattab
and Mark Lodato.
Details: git blame
;-)