wiki:notes/git

Version 13 (modified by root, at 2021-01-19T05:47:05Z) (diff)

--

заметки о git

инициализация репозитория

начиная с сервера

  • на сервере: git init --bare project.git;
  • на клиенте: git clone server.name.tld:repo/git/project.git project;
  • копируем содержимое исходников в директорию project и выполняем
    git add .
    git commit -a -m "inital release"
    git push origin master
    

начиная с клиента

cd project
git init
git add .
git commit -a -m "inital release"
git remote add origin server.name.tld:repo/git/project.git
git push origin master


синхронизация всех веток в bare репозиториях

git clone --bare url local.git
cd local.git
git config --add remote.origin.fetch '+refs/*:refs/*' 
git fetch


pull all branches to local

git branch -a | 
 sed -n \"/\\/HEAD /d; /\\/master$/d; /remotes/p;\" | 
 xargs -L1 git checkout -t"


pull single branch to local

git checkout -t remotes/origin/<branch_name>


drop last n commits

git reset --hard HEAD~n


update branch to master and top up unpushed commits

  • git pull --rebase origin master - in not pushed branch with local only commits. if something already pushed to remote it will desynchronize local and remote sides. in this case use:
  • git merge master - merge master commits to selected branch

or

  • git rebase master - rebase master commits to selected branch


edit, reword, squash, fixup, drop last n commits

git rebase -i HEAD~n


grep commit contents

git log -p --all -G clean_empty_state


github enterprise behavior

  • create a merge commit:
    • merge all commits from source branch into the middle of target branch;
    • create merge commit on top of target branch with all source commits as parents;
  • squash and merge:
    • squash all source commits into single commit;
    • add resulting commit on top of target branch;
  • rebase ant merge: add all commits from source branch on top of target branch


submodules

add

smp='ansible/roles/external/nginx-install';
git submodule add [email protected]:nginxinc/ansible-role-nginx.git ${smp}
git submodule set-branch --branch tags/0.19.1 -- ${smp} 
git add .gitmodules
(cd ${smp} && git checkout tags/0.19.1)

remove

git submodule deinit -f ${smp}
git add .gitmodules
git reset HEAD -- ${smp}
git rm -f ${smp}
rm -rf .git/modules/${smp} ${smp}