Склонировать репозиторий без истории
$ git clone --depth 1 https://github.com/Bubujka/ru.najomi.org-data.git
Сделать экспорт (аля svn export) ветки мастер в другую папку:
$ git archive master | tar -x -C /somewhere/else
Клонировать репозиторий
$ git clone ssh://user@somehost:port/~user/repository
$ git clone git://user@somehost:port/~user/repository/project.git
$ git clone http://user@somehost:port/~user/repository/project.git
$ git clone file:///home/username/project myrepo
# Этот вариант отличается от того, что начинается с file://
# Он работает быстрее, но утягивает заметно больше информации.
$ git clone /home/username/project myrepo
Редактировать конфиг в редакторе по умолчанию. Если не задан параметр --global, то редактируется .git/config, иначе ~/.gitconfig
$ git config -e [--global]
Добавить удаленный репозиторий
$ git remote add bob /home/bob/myrepo
Удалить файл из комита и с жесткого диска
$ git rm -f file1 file2 ... fileN
Отменить все изменения, сделанныe в дереве, до состояния, которое было при последнем commit в локальный репозиторий
$ git reset --hard
Удалить из индекса конкретный файл
$ git reset - EDITEDFILE
Удалить из папки документации к git все файлы txt
$ git rm Documentation/\*.txt
Навсегда удалить три последних коммита
$ git reset --hard HEAD~3
Отменить коммит
$ git revert config-modify-tag
$ git revert cgsjd2h
Просмотреть содержимое определённого коммита
$ git show d028769
commit d028769abbdcfa3e6cdba76cb1d6b569e5afe88e
Author: Aleksei Kaminin <zendzirou@gmail.com>
Date: Sun Aug 14 22:17:19 2011 +0400
Adde link to _nix category
diff --git a/_nix/meta.yaml b/_nix/meta.yaml
index bdb05a9..b107d80 100644
--- a/_nix/meta.yaml
+++ b/_nix/meta.yaml
@@ -14,3 +14,4 @@ keywords:
- примеры bsd
links:
- [http://www.opennet.ru/tips/sml/, 'много интересных заметок на разные темы']
+ - [http://www.linuxselfhelp.com/, 'большой сборник документаций']
Вывести информацию о том кто автор и когда менялись первые 3 строки файла README
$ git blame -L 1,+3 README
59246055 (Aleksei Kaminin 2011-08-04 15:00:12 +0400 1) Это репозиторий с ...
3426e293 (Aleksei Kaminin 2011-08-04 14:59:20 +0400 2)
3426e293 (Aleksei Kaminin 2011-08-04 14:59:20 +0400 3) Основной адрес: ht...
Попробовать объединить текущую ветку с веткой new_feature
$ git merge new_feature
Переименовать файл bug.c в файл feature.c
$ git mv bug.c feature.c
Посмотреть статистику коммитов по автору
$ git shortlog -s -n
118 Aleksei Kaminin
3 Alesenko Elena
3 Lena Omega
3 unknown
Взять коммит с номером 7496f529 и применить его к текущей ветке
$ git cherry-pick 7496f529
Взять правки из коммита 7496f529, применить их к текущей ветке, но сам коммит не совершать
$ git cherry-pick -n 7496f529
Изменить сообщение в предыдущем коммите
$ git commit --amend
Добавить изменения к предыдущему коммиту
$ git commit --amend -a
Cоздать tar-архив проекта и записать его в файл ~/prj.tar. Внутри него файлы будут находится в папке proj-1.2.3/
$ git archive --format=tar --prefix=proj-1.2.3/ HEAD > ~/prj.tar
Для каждой сделанной правки без коммита показать измененный участок кода и спросить, должно ли это изменение попасть в следующий коммит.
$ git add -p
Рекурсивно удалить все файлы в папке "vim/insert mode"
$ git rm -rf 'vim/insert mode'
Показать файл, как он выглядел коммит назад
$ git show HEAD^:view/prj/one_example.php
Кунг-фу по git-clean. TL;DR git clean -fdx удалить все новые файлы, пустые каталоги, и то что попадает под действие .gitignore Ключ -n вместо -f застаяляет git clean не выполнять реальных действий по удалению.
Создаём репозиторий
$ git init
Initialized empty Git repository in /home/waserd/tmp/.git/
$ touch a b c
$ mkdir tmp
$ touch tmp/lock
$ git add .
$ echo 'tmp/*' > .gitignore
$ git add .
$ git commit -m init
[master (root-commit) bce15e8] init
1 files changed, 1 insertions(+), 0 deletions(-)
create mode 100644 .gitignore
create mode 100644 a
create mode 100644 b
create mode 100644 c
create mode 100644 tmp/lock
Вносим в него различные правки
$ touch d tmp/{1,2,3}
$ ls > a
$ mkdir e
$ touch e/f
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: a
#
# Untracked files:
# (use "git add <file>..." to include in what will be committed)
#
# d
# e/
no changes added to commit (use "git add" and/or "git commit -a")
Смотрим что удалит git clean по умолчанию
$ git clean -n
Would remove d
Would not remove e/
Ключ -d удалит пустые каталоги заодно
$ git clean -nd
Would remove d
Would remove e/
А ключ -x удалит всё, будто .gitignore у нас нет.
$ git clean -ndx
Would remove d
Would remove e/
Would remove tmp/1
Would remove tmp/2
Would remove tmp/3
Удаляем
$ git clean -fdx
Removing d
Removing e/
Removing tmp/1
Removing tmp/2
Removing tmp/3
Почти чисто =)
$ git status
# On branch master
# Changed but not updated:
# (use "git add <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# modified: a
#
no changes added to commit (use "git add" and/or "git commit -a")
Удалить из индекса все файлы, что были удалены не через git.
$ rm b d foo/baz
$ git status
# On branch master
# Changed but not updated:
# (use "git add/rm <file>..." to update what will be committed)
# (use "git checkout -- <file>..." to discard changes in working directory)
#
# deleted: b
# deleted: d
# deleted: foo/baz
#
no changes added to commit (use "git add" and/or "git commit -a")
$ git add -u
$ git status
# On branch master
# Changes to be committed:
# (use "git reset HEAD <file>..." to unstage)
#
# deleted: b
# deleted: d
# deleted: foo/baz
#
Создать новый "голый" репозиторий my_project.git
$ git clone --bare my_project my_project.git
Initialized empty Git repository in /opt/projects/my_project.git/
Добавить право на запись для группы в репозиторий, который находится на сервере
$ ssh user@git.example.com
$ cd /opt/git/my_project.git
$ git init --bare --shared
Использовать графические инструменты для разрешения конфликтов при слиянии веток
$ git mergetool
merge tool candidates: kdiff3 tkdiff xxdiff meld gvimdiff opendiff emerge vimdiff
Merging the files: index.html
Normal merge conflict for 'index.html':
{local}: modified
{remote}: modified
Hit return to start merge resolution tool (opendiff):
Открыть страницу руководства Git по команде merge
$ git help merge
$ git merge --help
$ man git-merge
- 1 - sash-kan.blogspot.ru
- 2 - stackoverflow.com
- 3 - www.calculate-linux.ru
- 4 - cheat.errtheblog.com
- 5 - book.git-scm.com
- 6-7 - blog.nsws.ru
- 8-14, 17-18 - habrahabr.ru
- 15 - www-cs-students.stanford.edu
- 16 - stackoverflow.com
- 19-20 - www-cs-students.stanford.edu
- 21-22 - www-cs-students.stanford.edu
- 27-28 - progit.org
- 29 - progit.org
- 30 - progit.org
Ссылки по теме:
- www-cs-students.stanford.edu - Мануал по гиту