← На главную

Шпаргалка по Git

Тэги

Удаление старого тэга

git tag -d 0.17.0 
git push origin :0.17.0

Создание нового тэга

git checkout master 
git tag 0.17.0 -m "0.17.0" 
git push --tags

Клонирование с помощью другого ключа

git clone [email protected]:something.git
git clone git@gitlab_2:something.git
code ~/.ssh/config
Host           gitlab.com
    HostName       gitlab.com
    IdentityFile   ~/.ssh/id_rsa
    User           Username_1

Host           gitlab_2
    HostName       gitlab.com
    IdentityFile   ~/.ssh/id_rsa_2
    User           Username_2

Клонирование репозитория и смена адреса

git clone ssh://something.git 
git remote set-url origin ssh://something_2.git 
git checkout master

VS Code как редактор по-умолчанию

git config --global core.editor "code --wait" 
export EDITOR='code --wait'

Если ничерта не работает

git config core.filemode false

Сброс ветки к состоянию как в репозитории

git fetch --all 
git reset --hard origin/dev

Пуш в другую ветку

git checkout -b newbranch
git push -u origin newbranch

Догнать ветку

git merge master 
git pull --rebase origin master

Если сломался upstream

git branch --set-upstream-to origin/branch
git push --set-upstream origin branch

Склеивание коммитов

https://htmlacademy.ru/blog/useful/git/how-to-squash-commits-and-why-it-is-needed

git rebase -i HEAD~2 
squash 
fixup 
git log 
git push --force

Разделение коммитов

https://embeddedartistry.com/blog/2018/2/19/code-cleanup-splitting-up-git-commits-in-the-middle-of-a-branch

  1. Checkout the branch that you want to modify (e.g. pj/feature)
  2. Start an interactive rebase which includes your commit.
  3. Mark the commit(s) that you want to split with edit
  4. When git presents the commit that you want to split:
  5. Run git rebase --continue to resume or finish the rebase
git fetch 
git checkout branch
git merge origin/master
git checkout -b new-branch
git reset --hard origin/master 
git merge --squash branch

Если необходимо сменить почту на коммитах

https://www.git-tower.com/learn/git/faq/change-author-name-email/