Subversion Tracks Versions (Of a master copy, developers owns a working copies)
Git Tracks Changes (Stored as change sets shared between repositories)
Subversion User: Do we have our working directory files in a particular version of master copy files ?
Git User: Do we have a particular change sets applied to our repository/staged Area working directory files ?
(Click Git Logo)
Configuration Level | System | Global (User) | Project |
Configuration file location | Program Files\Git\etc\gitconfig | $HOME\.gitconfig | project_folder\.git\config |
$ git config --local
$ git config --global
$ git config --system
$ git config --global user.name "John Doe"
$ git config --global user.email johndoe@example.com
# Options :
# --list (-l), --edit (-e)
$ git help <verb>
# Or
$ git <verb> --help
# Or
$ man git-<verb>
.../project_folder $ git init
Tell Git to start tracking
.git folder is the Git workspace
To untrack a project, just remove the .git folder
.svn everywhere...
# check files status
$ git status
# tell git to add current folder to what will be committed
$ git add .
# check files status
$ git status
# tell git to track this changes (not this version)
$ git commit -m "init"
# check files status
$ git status
$ git log -n 10
$ git log --since=2012-06-15
$ git --until=2012-06-18
$ git log --author "maeljirari"
$ git grep "init"
Working Directory
Repository
commit
update
2-Trees Architecture
3-Trees Architecture
$ git status
"Git generates a checksum for each committed change set."
If data changes, checksum changes => Data integrity
5a8e8f
a99ea4
98e44f
WD
WD
WD
SA
SA
SA
Repository
Repository
Repository
commit
commit
commit
commit
commit
add
add
add
Commit : pointer to changes stored as change sets (snapshot of changed files)
HEAD : pointer to the parent of the next commit in the current checked branche
# checkout particular file
$ git checkout -- <file>
# checkout the whole branch
$ git checkout <branch>
# changes will persist in our working directory, reset only the staging area
# to look like repository
$ git reset HEAD <file>
# change last commit, commit that HEAD still point to
$ git commit --amend -m "commit message"
# retrieve an old version of a file and put it directly to staging area
$ git checkout <commit> -- <file>
# commit
$ git commit -m "commit message"
# create a mirror commit that abort previous commit, will do a commit
$ git revert <commit>
# create a mirror commit that abort previous commit, will stage it
$ git revert -in <commit>
Local and remote repositories
# for local repository
# make a commit and move HEAD pointer
# to point to that commit
$ git reset <commit>
Only Local repositories
$ git add <pathspec>
# add current folder
$ git add .
# add file
$ git add <file>
Add files to staging index (to what will be committed)
$ git diff
$ git diff --cached
# remove the file only from the Git repository and the filesystem
$ git rm <file>
$ git commit -m "remove file"
# remove the file only from the Git repository
# and not remove it from the filesystem
$ git rm --cached <file>
# move file
$ git mv <source> <destination>
# rename file
$ git rm <file>
Discussion
Discussion
Discussion
# basic regular expression
* ? [aeiou] [0-9]
# negate expressions with !
*.txt
!myFile.txt
# ignore all files in a directory with a trailing slash
assets/videos/
project_folder/.gitignore
# global ignore file, used by all git repositories (not committed, not pushed)
$ git config --global core.excludesfile '~/.gitignore'
Add a .gitignore file to the home directory
Files must be untracked before being ignored
remove untracked files from the repository and working copy
# remove file from repository and working directory
$ git rm <file>
remove untracked files from the staging index
# remove file from staging index only, copy still in working
# directory and repository
$ git rm --cached <file>
clean untracked files
# remove all untracked files, dangerous
$ git clean
# safer option
$ git stash --all
add an empty file named .gitkeep
Text
branch = list of commits
# create a testing branch
$ git branch testing
$ git status
# checking out test branch
$ git checkout test
# checking out master branch
$ git checkout master
Switching on a clean directory
Commit your changes or stashes them
then
siwtch branch
# order is not important
$ git diff <branch1>..<branch2>
# show branches that are completely merged with the current branch
$ git branch --merged
# rename the current branch
$ git branch -m <new_name>
# rename branch
$ git branch -m <old_name> <new_name>
# delete a local merged branch
git branch -d <branch>
# delete a local not merged branch
git branch -D the_local_<branch>
True Merge
1
2
1
3
4
2
Simple divergent history
Merging to integrate diverged work history
Rebasing the change introduced in C4 onto C3
Fast-forwarding the master branch
A history with a topic branch off another topic branch
Rebasing a topic branch off another topic branch
Fast-forwarding your master branch to include the client branch changes
Rebasing your server branch on top of your master branch
Final commit history
1
2
3
4
5
Classical
Classical
"Stashing takes the dirty state of your working directory – that is, your modified tracked files and staged changes – and saves it on a stack of unfinished changes that you can reapply at any time."
$ git status
$ git stash
$ git status
$ git stash list
# apply last stash
$ git stash apply
# apply specific stash
$ git stash list
$ git stash apply stash@{1}
# create a branch from stash
$ git stash branch <branch>
$ git stash list
$ git stash drop stash@{1}
$ git stash list
$ git remote
$ git remote -v
$ git remote show
$ git remote show <remote_name>
$ git remote add <remote_name> <remote_url>
$ git push <remote_name> <branch_name>
$ git push -u <remote_name> <branch_name>
Server and local repositories after cloning
No more connection between remote repositories
$ git checkout -b [local_branch_name] [remote_name]/[remote_branch_name]
$ git branch -u origin/serverfix
$ git push <remote_name> <branch_name>
# fetch all changes that you don't have yet
$ git fetch <remote_name> <branch_name>
$ git merge <branch_name>
$ git merge --rebase <branch_name>
$ git checkout -b [branch] [remotename]/[branch]
Pull before Push
$ git push <remote_name> --delete <branch_name>
(click Github Logo to access SSH Help)
(click EGit Logo)
Next : SASS Essentials