om om GIT - Tips & Tricks / git.dvcs git-tips.com
What is non-linear is a distributed revision control system with an emphasis on speed, data integrity, and support for distributed, non-linear workflows.
History SCSS Closed source Save original file Save snapshot of changes To get the latest version get version 1 add version 2 add version Work only on single file
History RCS Open source Cross platform Save latest version as most recent and changes are applied backward Much faster then SCSS Work only on single file
History CVS Work on multiple file Remote repository Allow Concurrent users to work at same time on same file(s) Capture changes to every single file Shared work
History BitKeeper Closed source Used for the linux kernel DVCS (Distributed Version Control) Stopped to be free in 2005
History SVN Faster then CVS Allowed saving binary data (images etc) Capture changes not on only to files or group of files but to whole directory. Takes a snapshot of the directory and not the files Shared work Can track file renames
April 2005
Born April 2005 Up to 200x faster then SVN DVCS Integrity check (SHA1) Branches are free Cross platform Compact love have You love it or have it
Why developers hate GIT CLI - most of the work needs to be done from command line Very Complex (thousands !!! of command options) git-config.html git-log.html git-config.html git-log.html Hard to learn Merge can be nightmare [5 different merge strategies !!!][5 different merge strategies !!!] Fast forward vs Not fast forward
Small example: Question: Is git case sensitive ? How does it handle case sensitive renamed files?Answer: Do Not !!! Try it at home ( * git mv)
Key Features
DVCS The Three States Hashes Change sets / snapshots Branches Fast forward vs Non fast forward Merge / Rebase
(DVCS) Key Features (DVCS) No need for central repository No network in needed = we can work offline Faster - no date needs to be sent to server (SVN: lock) Each copy it a full repo Each repository can be unique (contain its own change sets) Branches (Local) Reliability - no server down time or corrupted data
(3 states) Key Features (3 states)
(snapshots) Key Features (snapshots) CVS/SVN use deltas calculate With long histories, becomes heavy to calculate current files state
(snapshots) Key Features (snapshots) git all your files snapshot Every time you commit, or save the state of your project in git, it basically takes a picture of what all your files look like at that moment and stores a reference to that snapshot.
(snapshots) Key Features (snapshots)
Hands On
Installing
Installing Windows: download installer Mac (pre installed with OS) Unix – sudo apt-get update sudo apt-get install git
Configuration
.gitconfig
.gitconfig Git has 3 configuration levels System Global (User) Project
.gitconfig The configuration fall into two categories client side server side
.gitconfig The command is git config Project level: git config user.name "Nir Geier" Global level: git config --global user.name "Nir Geier" System level: git config --system user.name "Nir Geier"
.gitconfig (initial configuration) $ git config --global user.name “Nir Geier” Sets the name you want attached to your commits $ git config --global user. Sets the you want attached to your commis $ git config --global color.ui auto Enables helpful colorization of command line output
.gitconfig.gitconfig [ alias ] Same as Unix aliases – execute long commands using shortcut
.gitconfig.gitconfig [ alias ] Aliases can be simple or complicated Simple alias: ls = git log --oneline
.gitconfig.gitconfig [ alias ] Aliases can be a custom function ra = "!f() { git remote add $1 }; f"
.gitconfig.gitconfig [ alias ] complex function : "!bash -c ‘source ~/.githelpers && pretty_git_log’ "
.gitignore
.gitignore Git can be configured to ignore certain files and directories..gitignore This is configured in a.gitignore file. This file can be in any directory and can contain patterns for files. *.class ex: *.class.gitignore is parsed in a commutative way from top to bottom (system /global / root folder/ inner folder)
.gitignore Note (1): --force git add --force [filename] You can still add ignored files to the staging area of the Git repository by using the --force parameter, i.e. git add --force [filename] command.
.gitignore Note (2): Files that are committed to the Git repository are not automatically removed if you add them to a.gitignore file. You can use the git rm -r --cached [filename] command to remove existing files from a Git repository.
.gitkeep
Commands
Most common commands git init / clone git status git add git rm git commit git checkout git log
git init
Starting new project: git init [--bare] *git flow init Joining existing project (Fetching remote repository): git clone
git status
Display the working tree status 1.Differences between the index file and the current HEAD commit. 2.Differences between the working tree and the index untracked files.
git status
git add
Before Before committing change to a git repository you need to mark the changes that should be committed. This is done by adding the new and changed files to the staging area. snapshot This creates a snapshot of the affected files.
git add Note: In case you change one of the files again before committing, you need to add it again to the staging area to commit the new changes. git add. git add -A.
git rm
Remove files from the index, or from the working tree and the index. If you delete a file which is under version control, git add. does not record this file deletion. You can use the git rm command to delete the file from your working tree and record the deletion of the file in the staging area.
git rm
git commit
Add the stages files to the local repository git commit git commit -m git commit -am git commit --amend
git checkout
Checkout a branch or paths to the working tree When used on files/paths = discard changes
om om GIT - Tips & Tricks / git.dvcs git-tips.com