Upload
2-
View
645
Download
1
Embed Size (px)
Citation preview
Приручаем GitСергей Коржнев
2GIS
GIT? WTF?● stupid. contemptible and despicable. simple.
Take your pick from the dictionary of slang.
● "global information tracker": you're in a good mood, and it actually works for you. Angels sing, and a light suddenly fills the room.
● "goddamn idiotic truckload of sh*t": when it breaks
Просто забавная картинка
Хранение данных в SVN
Хранение данных в GIT
Конфигурация
Файлы:● /etc/gitconfig (git config --system)● ~/.gitconfig (git config --global)● .git/config (git config)
$git config --global user.name "John Smit"$git config --global user.email [email protected]
$git config --list
Конфигурация. Красота.[color] branch = auto diff = auto interactive = auto status = auto[alias] st = status ci = commit co = checkout br = branch hist = log --pretty=format:\"%h %ad | %s%d [%an]\" --graph --date=short
Просто красота.############################################################################# Apply Git and Subversion Integrationif [ -f /opt/local/etc/bash_completion.d/git ]; then. /opt/local/etc/bash_completion.d/gitfiscm_ps1() {local s=if [[ -d ".svn" ]] ; thens=\(svn:$(svn info | sed -n -e '/^Revision: \([0-9]*\).*$/s//\1/p' )\)elseif [[ $(declare -f __git_ps1) ]]; then # Only show if completion is thereGIT_PS1_SHOWDIRTYSTATE=trueGIT_PS1_SHOWSTASHSTATE=trueGIT_PS1_SHOWUNTRACKEDFILES=trues=$(__git_ps1 "(git:%s)")fifiecho -n "$s"}#export PS1="\[\033[00;32m\]\u\[\033[00;32m\]@\[\033[00;32m\]\h:\[\033[01;34m\]\w\[\033[31m\]\$(scm_ps1)\[\033[00m\]$ "export PS1="${debian_chroot:+($debian_chroot)}\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]\w\[\033[01;33m\]\$(scm_ps1)\[\033[00m\]\$ "#PS1='\[\033[01;32m\]\u@\h\[\033[00m\] \[\033[01;34m\]\W\[\033[01;33m\]$(__git_ps1 " (%s)")\[\033[00m\]\$ '############################################################################
git diff
● Измененные файлы еще не в индексеgit diff
● Измененные файлы уже в индексеgit diff --stagedgit diff --cached (git version < 1.6.1)
git commit
● git commit -a -m "description"
Выведение файла из под контроля GIT
● git rm --cached readme.txt
Изменение последнего комита
$ git commit$ git commit --amend
$ git commit -m "initial commit"$ git add forgotten_file$ git commit --amend
Note: меняется hash-коммита
Отмена индексации файла
Changes to be commited: (use "git reset HEAD <file>..." to unstage)
Отмена изменений файла
git checkout readme.txtgit checkout .
Fetch и Pull
$ git fetch [remote-name] - стягивает данные с удаленного репозитория, но не пытается мержить с локальными доработками
git pull - делает то же самое, что и fetch, но с мержем
Теги
● git tag -a v1.2 9fceb02 - добавить опосля● git push - не отправляет теги
○ git push origin v1.5 - отправляет○ git push origin --tags
Ветки
Создание ветки
● git branch <branch-name>● git checkout -b <branch-name>
$ git branch testing
$ git checkout testing
$ vim test.rb$ git commit -a -m 'made a change'
Merge. "Fast-forward" (перемотка).$ git checkout master$ git merge hotfix
Merge. Трехходовое слияние.
Merge. Трехходовое слияние.
Rebase
Rebase
$ git checkout experiment$ git rebase master
Rebase
$ git checkout master$ git merge experiment
Rebase
$ git rebase --continue
$ git rebase --skip - пропустить наложение коммита и перейти к следующему
$ git rebase --abort - отмена работы команды и всех внесенных изменений
Управление ветками
● git branch -v - ветки + их последние коммиты
Удаленные ветки
Удаленные ветки
Удаленные ветки
Отслеживание веток
● Создание локальной ветки, связанной с удаленной
$ git checkout --track origin/serverfixBranch serverfix set up to track remote branch refs/remotes/origin/serverfix.Switched to a new branch "serverfix"
● Удаление веток на удаленном сервере$ git push origin :serverfixTo [email protected]:schacon/simplegit.git - [deleted] serverfix
RefLog-сокращения
● git reflog7fa2b31 HEAD@{0}: checkout: moving from WAPI-3160-tracker to WAPI-3574-base-api14bbe6894 HEAD@{1}: checkout: moving from master to WAPI-3160-trackerbbe6894 HEAD@{2}: merge WAPI-3160-tracker: Fast-forward110b3ad HEAD@{3}: checkout: moving from WAPI-3160-tracker to masterbbe6894 HEAD@{4}: merge master: Merge made by recursive.462c426 HEAD@{5}: checkout: moving from master to WAPI-3160-tracker110b3ad HEAD@{6}: pull : Fast-forward
Диапазон комитов
$ git log master..experimentDC
$ git log experiment..masterFE
Бинарный поиск$ git bisect start$ git bisect bad$ git bisect good v1.0...$ git bisect good...$ git bisect bad
...$ git bisect reset
Git resetgit reset --soft HEAD^ - переходим в состояние перед коммитом
git reset --hard HEAD^ - сносим последний комит полностью
Other● git revert 12abacd - создаем коммит,
откатывающий коммит (фактически именно последний коммит)
● git show <hash>● git blame <hash> (git annotate <hash>)● git grep ...● git branch -D new-branch — удалит ветку в
любом случае.● git branch -m new-name-branch —
переименует ветку. (?)● git cherry-pick <hash>
Источники● http://habrahabr.ru/post/150673/ - книга
"Pro Git"● http://habrahabr.ru/post/60347/ - cool статья