git basics
- life before git (tarballs+patches, bitkeeper, many discussions about licence, reverse engineering of bk, seperate ways...")
- then use what? (requirements: distributed, robust, fast) -> none were qualified
- Linus: "I can write something better in two weeks". And he did!
- git as as an prime example of software engineering under Unix
- git objects are identified by SHA1 sums!
- objects:
- blobs (file contents)
- trees (blobs or other trees)
- commits (tree, parent commits, message)
- tags (object (usally commit), name (2.6.26), message, signature)
- one SHA1 commit describes complete history (uniquely, cryptographically strong)
- 3 stages: working dir -> index (stage area) git-object db
Configuration
introduce yourself:
$ git config --global user.name "Your Name Comes Here"
$ git config --global user.email you@yourdomain.example.com
Create a new repository
$ git-init-db
$ git-add .
$ git-commit
Working with existing repositories
Best practice: work on a branch and leave master branch unmodified (track upstream)
clone a repository:
$ git-clone git://www.denx.de/git/linux-denx.git
look at the history
$ git-log # simple
$ tig # tui
add a branch for hacking
$ git-checkout -b hacking HEAD
edit some files and look at changes in working dir
$ git diff
add modified files to the index:
$ git add file1 file2
delete some and mark them as deleted:
$ git rm file3
look at diffs of the modified files added to the index
$ git diff --cached
get some general statistics of which files were modified:
$ git status
to throw away the changes
git reset HEAD
, to reset the working directory
git-checkout -f
commit the changes added to the index (will be prompted for commit message)
$ git commit # -s adds Signed-off-by: ... line
alternatively without using the index as an intermediate stage:
$ git commit -a
unhappy with commit message?
$ git commit --amend
local branches
what branches have we got?
git branch
create a branch as a clone of the current branch:
$ git branch hacking
check out the contents of this branch:
git checkout hacking
hack around, make a mess of it and decide to throw it away
git checkout -f
git checkout master
git branch -d hacking
git for developers
- git mostly aims at making the maintainers life easier
- conflict: maintainers expect logical separation of features but developers need to
- commit often (traceable development)
- rework code they have already committed
- some tools, e.g. stacked git make things easier for developers
- git's solution: rebasing nice description here
- idea is to commit often during development and later "squash" commits into logical ones
Example: rework last 5 commits
$ git-rebase --interactive HEAD~5
move around lines and change
pick
into
squash
in order to merge commit into previous one.
$ git rebase --abort
goodies
- whos fault is it:
git-blame
- which commit introduced the bug:
git-bisect
- maintain a clean repository:
git-gc
- check repository for consistence:
git-fsck
- remove all those untracked files:
git-clean
(=-df)
- tree too big?
- use a shared repository (objects on demand)
git-clone -s
-
git-clone --reference
: reference a local repository
- make a shallow copy:
git-clone --depth