This shows you the differences between two versions of the page.
Both sides previous revision Previous revision Next revision | Previous revision Next revision Both sides next revision | ||
сервис_git [2020/05/12 20:52] val [Подготовка сетевого http репозитория] |
сервис_git [2023/05/25 14:34] val [Пример с тестовой веткой] |
||
---|---|---|---|
Line 1: | Line 1: | ||
====== Сервис Git ====== | ====== Сервис Git ====== | ||
+ | |||
+ | * [[https://ru.wikipedia.org/wiki/Git|Git - Википедия]] | ||
* [[https://git-scm.com/book/ru/v2/|The entire Pro Git book (на русском)]] | * [[https://git-scm.com/book/ru/v2/|The entire Pro Git book (на русском)]] | ||
* [[http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/|8 ways to share your git repository]] | * [[http://www.jedi.be/blog/2009/05/06/8-ways-to-share-your-git-repository/|8 ways to share your git repository]] | ||
* [[http://hyperprog.com/howto/etc-git.html|How-To store /etc in a git repository on debian linux]] | * [[http://hyperprog.com/howto/etc-git.html|How-To store /etc in a git repository on debian linux]] | ||
+ | * [[https://git-scm.com/download/win|Git for Windows]] | ||
+ | * [[https://git-lfs.github.com/|An open source Git extension for versioning large files]] | ||
+ | |||
+ | * [[https://www.theserverside.com/feature/Why-GitHub-renamed-its-master-branch-to-main|Why GitHub renamed its master branch to main]] | ||
+ | |||
+ | * [[https://youtu.be/SEvR78OhGtw|youtube/Артем Матяшов/Git. Большой практический выпуск (youtube)]] | ||
===== Работа с локальным репозиторием ===== | ===== Работа с локальным репозиторием ===== | ||
- | * Вместо "искусственного" каталога /root/conf/ можно использовать /etc/ или /srv/tftp/ | + | * Вместо каталога conf/ можно использовать /etc/ или /srv/tftp/ |
<code> | <code> | ||
- | server.corpX.un:~# mkdir conf | + | server:~$ mkdir conf |
- | server.corpX.un:~# cd conf/ | + | server:~$ cd conf/ |
- | server.corpX.un:~/conf# echo Hello World > file1 | + | server:~/conf$ echo Hello World > file1 |
- | server.corpX.un:~/conf# mkdir dir1 | + | server:~/conf$ mkdir dir1 |
- | server.corpX.un:~/conf# echo Hello World 2 > dir1/file2 | + | server:~/conf$ echo Hello World 2 > dir1/file2 |
- | server.corpX.un:~/conf# git init | + | server:~/conf$ git init |
- | server.corpX.un:~/conf# git add . | + | server:~/conf$ git add . |
- | server.corpX.un:~/conf# git status | + | server:~/conf$ git status |
- | server.corpX.un:~/conf# git commit -a -m 'ver: 1.1' | + | server:~/conf$ git config --global user.email "student@corpX.un" |
+ | server:~/conf$ git config --global user.name "FIO" | ||
- | server.corpX.un:~/conf# echo Hello World 3 > file1 | + | server:~/conf$ git commit -a -m 'ver: 1.1' |
- | server.corpX.un:~/conf# git status | + | server:~/conf$ echo Hello World 3 > file1 |
- | server.corpX.un:~/conf# git add -v . | + | server:~/conf$ git status |
- | server.corpX.un:~/conf# git status | grep 'modified\|deleted\|new file\|renamed' | git commit -a -F - | + | server:~/conf$ git add -v . |
- | server.corpX.un:~/conf# git log | + | server:~/conf$ git --no-optional-locks status | grep 'modified\|deleted\|new file\|renamed' | git commit -a -F - |
- | server.corpX.un:~/conf# git log --follow -- file1 | + | server:~/conf$ git log |
- | server.corpX.un:~/conf# git show <commit hash>:file1 | + | server:~/conf$ git log --follow -- file1 В каких коммитах менялся файл |
- | server.corpX.un:~/conf# git diff <commit hash> file1 | + | server:~/conf$ git show <commit hash> Все изменения файлов в этом коммите по |
- | server.corpX.un:~/conf# git diff <commit hash N> <commit hash M> file1 | + | server:~/conf$ git show <commit hash>:file1 Содержимое файла в этом коммите |
+ | |||
+ | server:~/conf$ git show <commit hash> file1 Изменения файла между этим и предыдущим коммитом | ||
+ | |||
+ | server:~/conf$ git diff <commit hash> file1 Изменения файла после этого коммита | ||
+ | |||
+ | server:~/conf$ git diff <commit hash N> <commit hash M> | ||
+ | |||
+ | server:~/conf$ git diff <commit hash N> <commit hash M> file1 | ||
</code> | </code> | ||
- | ===== Подготовка сетевого http репозитория ===== | + | |
+ | ===== Пример с использованием cron ===== | ||
<code> | <code> | ||
- | server# mkdir /var/www/html/conf.git | + | # cat /etc/cron.daily/my-git-etc |
+ | </code><code> | ||
+ | #!/bin/sh | ||
- | server# cd /var/www/html/conf.git | + | for d in /etc/ /root/ |
+ | do | ||
+ | cd $d | ||
+ | [ -d $d/.git ] || git init > /dev/null | ||
+ | git add . | ||
+ | git --no-optional-locks status | grep 'modified\|deleted\|new file\|renamed' | git commit -a -F - > /dev/null | ||
+ | done | ||
+ | |||
+ | exit 0 | ||
+ | </code> | ||
+ | |||
+ | ===== Создание сетевого http/ssh git репозитория ===== | ||
+ | <code> | ||
+ | server:~# mkdir /var/www/html/conf.git | ||
+ | |||
+ | server:~# cd /var/www/html/conf.git | ||
server#:/var/www/html/conf.git# git init --bare | server#:/var/www/html/conf.git# git init --bare | ||
Line 56: | Line 92: | ||
server#:/var/www/html/conf.git# chmod a+x hooks/post-update | server#:/var/www/html/conf.git# chmod a+x hooks/post-update | ||
+ | </code> | ||
+ | Не обязательно, но, если хочется видеть содержимое текущего репозитория по http, можно поправить hooks/post-update | ||
+ | <code> | ||
+ | server#:/var/www/html/conf.git# cat hooks/post-update | ||
+ | </code> | ||
+ | !!! exec должна быть последняя команда | ||
+ | <code> | ||
+ | ... | ||
+ | #exec git update-server-info | ||
+ | git update-server-info | ||
+ | |||
+ | rm -rf conf | ||
- | server/var/www/html/conf.git# cat hooks/post-update | + | exec git clone http://server.corpX.un:81/conf.git |
</code><code> | </code><code> | ||
- | ... | + | server:~# chown -R student /var/www/html/conf.git/ |
- | git clone http://server.corpX.un/conf.git | + | |
- | exec git update-server-info | + | |
- | </code><code> | + | |
- | server# chown -R student /var/www/html/conf.git/ | + | |
</code> | </code> | ||
+ | |||
+ | * Обновление [[#Персонального http/ssh git репозитория]] | ||
===== Обновление сетевого репозитория из локального ===== | ===== Обновление сетевого репозитория из локального ===== | ||
- | ==== Использование персонального репозитория ==== | + | * [[https://dzen.ru/a/YufH0P_uAEpuxnPg|Работа с тегами Git: создание, удаление, использование]] |
+ | ==== On-Premise gitlab ==== | ||
+ | |||
+ | * [[https://stackoverflow.com/questions/6565357/git-push-requires-username-and-password|Git push requires username and password]] | ||
<code> | <code> | ||
- | server.corpX.un:~/conf# git remote add origin file:///var/www/html/conf.git | + | $ git remote -v |
- | server.corpX.un:~/conf# git remote -v | + | $ git remote remove origin |
- | server.corpX.un:~/conf# git push origin master | + | $ git remote add origin http://server.corpX.un/student/dhcp.git |
- | server.corpX.un:~/conf# echo Hello World 4 > dir1/file2 | + | $ git branch |
- | server.corpX.un:~/conf# git status | + | $ ### git config credential.helper store |
- | server.corpX.un:~/conf# git add . | + | $ git push origin master |
- | server.corpX.un:~/conf# git commit -a -m 'ver: 1.3' | + | $ ### cat ~/.git-credentials |
- | server.corpX.un:~/conf# git push origin master | + | $ git tag ver03 |
+ | |||
+ | $ git push origin ver03 | ||
</code> | </code> | ||
+ | |||
==== github.com ==== | ==== github.com ==== | ||
<code> | <code> | ||
- | gate:~/zabbix_dhcp_pools# git remote add origin https://github.com/valbmsturu/zabbix_dhcp_pools.git | + | gate:~/zabbix_dhcp_pools$ git remote add origin https://github.com/valbmsturu/zabbix_dhcp_pools.git |
- | gate:~/zabbix_dhcp_pools# git push -u origin master | + | gate:~/zabbix_dhcp_pools$ git push -u origin master |
</code> | </code> | ||
- | ===== Создание и обновление локального репозитория из сетевого ===== | ||
- | ==== Использование персонального репозитория ==== | + | ==== Персонального http/ssh git репозитория ==== |
<code> | <code> | ||
- | gate.isp.un:~$ git clone http://server.corpX.un/conf.git | + | server:~/conf$ git remote add origin file:///var/www/html/conf.git |
- | gate.isp.un:~$ cd conf/ | + | server:~/conf$ git remote -v |
- | gate.isp.un:~/conf$ cat dir1/file2 | + | server:~/conf$ git remote rm origin |
- | gate.isp.un:~/conf$ git pull origin master | + | server:~/conf$ git remote add origin ssh://student@server.corpX.un/var/www/html/conf.git |
- | gate.isp.un:~/conf$ cat dir1/file2 | + | server:~/conf$ git push origin master |
+ | |||
+ | server:~/conf$ echo Hello World 4 > dir1/file2 | ||
+ | |||
+ | server:~/conf$ git status | ||
+ | |||
+ | server:~/conf$ git add -v . | ||
+ | |||
+ | server:~/conf$ git commit -a -m 'ver: 1.3' | ||
+ | |||
+ | server:~/conf$ git push origin master | ||
</code> | </code> | ||
+ | |||
+ | ==== val.bmstu.ru ==== | ||
+ | <code> | ||
+ | ~/conf# val$ cat readme.txt | ||
+ | </code> | ||
+ | |||
+ | ===== Клонирование и обновление локального репозитория из сетевого ===== | ||
+ | |||
+ | ==== On-Premise gitlab ==== | ||
+ | <code> | ||
+ | # git clone http://server.corpX.un/student/dhcp.git | ||
+ | |||
+ | или | ||
+ | |||
+ | student@gate:~/dhcp$ git pull origin master | ||
+ | </code> | ||
+ | |||
==== github.com ==== | ==== github.com ==== | ||
<code> | <code> | ||
# git clone https://github.com/valbmsturu/zabbix_dhcp_pools.git | # git clone https://github.com/valbmsturu/zabbix_dhcp_pools.git | ||
+ | |||
+ | ... | ||
</code> | </code> | ||
+ | |||
+ | ==== Персонального http/ssh git репозитория ==== | ||
+ | <code> | ||
+ | gate.isp.un:~$ git clone http://server.corpX.un:81/conf.git | ||
+ | |||
+ | gate.isp.un:~$ cd conf/ | ||
+ | |||
+ | gate.isp.un:~/conf$ less dir1/file2 | ||
+ | |||
+ | gate.isp.un:~/conf$ git pull origin master | ||
+ | |||
+ | gate.isp.un:~/conf$ less dir1/file2 | ||
+ | </code> | ||
+ | |||
==== val.bmstu.ru ==== | ==== val.bmstu.ru ==== | ||
<code> | <code> | ||
- | git clone http://val.bmstu.ru/unix/conf.git | + | $ git clone http://val.bmstu.ru/unix/conf.git |
+ | |||
+ | ... | ||
+ | </code> | ||
+ | |||
+ | ===== Работа с ветками ===== | ||
+ | |||
+ | * [[https://stackoverflow.com/questions/2003505/how-do-i-delete-a-git-branch-locally-and-remotely|How do I delete a Git branch locally and remotely?]] | ||
+ | * [[https://stackoverflow.com/questions/10312521/how-do-i-fetch-all-git-branches|How do I fetch all Git branches?]] | ||
+ | ==== Пример с тестовой веткой ==== | ||
+ | <code> | ||
+ | λ git branch test | ||
+ | |||
+ | λ git branch -a | ||
+ | |||
+ | λ git checkout test | ||
+ | |||
+ | ... edit ... add ... commit ... | ||
+ | |||
+ | λ git push origin test | ||
+ | |||
+ | root@server:~/openvpn1# git pull origin test | ||
+ | root@server:~/openvpn1# ansible-playbook ... test_nodes | ||
+ | или | ||
+ | ... ci/cd test ... | ||
+ | |||
+ | |||
+ | λ git checkout main | ||
+ | λ git checkout master | ||
+ | |||
+ | λ git merge test | ||
+ | |||
+ | ... commit ... | ||
+ | |||
+ | λ git push -u origin main | ||
+ | λ git push -u origin master | ||
+ | |||
+ | ... ci/cd prod ... | ||
+ | |||
+ | λ git push -d origin test | ||
+ | λ git branch -d test | ||
+ | |||
+ | val@bro:~/conf$ git fetch --all | ||
+ | </code> | ||
+ | |||
+ | ==== Пример установки ПО ==== | ||
+ | |||
+ | <code> | ||
+ | # dpkg -l | grep mediawiki | ||
+ | ii mediawiki 1:1.31... | ||
+ | ... | ||
+ | |||
+ | # cd /var/lib/mediawiki/extensions/ | ||
+ | |||
+ | # git clone https://gerrit.wikimedia.org/r/p/mediawiki/extensions/UserMerge | ||
+ | |||
+ | # cd UserMerge/ | ||
+ | |||
+ | # git branch -r | ||
+ | |||
+ | # git checkout REL1_31 | ||
</code> | </code> |