Первоначальная настройка Git
git config --global user.name "Nikolay Rozhkov"
git config --global user.email rozhkov@uchi.ru
Внешиние утилиты
git config --global diff.tool meld
git config --global difftool.prompt false
git config --global core.editor /usr/bin/vim
External diff
[diff]
tool = meld
[difftool]
path = meld
prompt = false
External editor
[core]
editor = /usr/bin/vim
Init
Инициализировать новый проект c Git
git init new-project
git init new-project --bare
Добавить существуй проект в Git
cd existing-project
git init
git init .
Add
git add .
Reset
git reset
Remove
git rm
git add -A
git add --all
git status
git commit
git commit -m 'Here goes message'
Изменение последнего коммита
git commit --amend
Отмена изменений файла
git checkout -- hello.txt
Создание ветки
git branch feature
Переключение
git checkout feature
Сокращённо
git checkout -b feature
Список веток
$ git branch --all
* master
Новая ветка
Разработка
Слияние fast-forward, "Перемотка"
git checkout master
git merge feature
Слияние --no-ff
git checkout master
git merge --no-ff feature
Слияние при наличии других коммитов
Revert
git revert HEAD~1
git checkout feature && git rebase master
Interactive Rebase
git co -b before-rebase
for i in `seq 10 30`; do echo $i > $i && git add . && git cm -m$i ; done
git co -b after-rebase
git rebase -i HEAD~21 # master
# Rebase cc9a7b9..10cf5fa onto cc9a7b9 (21 command(s))
#
# Commands:
# p, pick = use commit
# r, reword = use commit, but edit the commit message
# e, edit = use commit, but stop for amending
# s, squash = use commit, but meld into previous commit
# f, fixup = like "squash", but discard this commit's log message
# x, exec = run command (the rest of the line) using shell
# d, drop = remove commit
git cherry-pick cc9a7b9
git init uchi && cd ..
git clone uchi -o source local
cd local && git branch -m main
git branch --unset-upstreamgit branch --set-upstream-to=source/master
cat .git/config
[remote "originsource"]
url = /tmp/uchi
fetch = +refs/heads/*:refs/remotes/originsource/*
[branch "mastermain"]
remote = originsource
merge = refs/heads/masterremote = source
merge = refs/heads/master
git clone uchi -o source local
...
git fetch source
git fetch && git merge source/master
git pull source
Notation
local-branch:remote-branch
Uptrack
git push -u source feature
Delete
git push source :topic
git push source --delete topic
Resolve conflicts
git rebase master
git pull --rebase
git checkout --ours file.txt # feature
git checkout --theirs file.txt # master
Detached
git checkout 26c0aa12792e6344f5
git checkout 26c0aa12792e6344f5 -b feature
$ git show ???
Возможные значения
master
v1
b1713c7
Возможные значения
HEAD@{0}
HEAD^
HEAD~
Выбираем SHA
$ git log
commit b1713c78427b728a2d981981dccb5d6e398b66a6
Author: Nikolay Rozhkov <rozhkov@uchi.ru>
Date: Wed Jun 21 19:20:54 2017 +0300
Fixed env
commit 47194bcc4a1413360b42a15f1067605162f58d29
Author: vbratkev <bratkevich.v@gmail.com>
Date: Tue Jun 20 15:15:26 2017 +0300
Fix deploy
Выбираем перемещения HEAD
$ git reflog
b1713c7 HEAD@{0}: commit: Fixed env
47194bc HEAD@{1}: clone: from git@github.com:nirname/documentary.git
$ git show HEAD@{1}
Выбираем родителей
HEAD^n
n-й родитель
HEAD~n
n 1-x родителей
HEAD^1^1 == HEAD~2
Выбираем родителей
HEAD^ == HEAD^1
HEAD~ == HEAD~1
HEAD == HEAD^0 == HEAD~0
Выбираем родителей
Выбираем родителей
Bisect
git bisect start
git bisect bad
git bisect good master
git bisect start HEAD master
git bisect run test -f hello.txt
git push -f
git push -u origin feature
git push -u origin feature && git rebase master
git rebase master && git push -u origin feature
git pull --rebase
git merge --no-ff master && git pull --rebase
git rebase --abort
git merge --abort
git reset --hard HEAD~
git revert HEAD
git checkout '**'
git clean -df
git branch -D feature
Прочитать
https://git-scm.com/book/en/v2
https://git-scm.com/book/ru/v1