Skip to content

Instantly share code, notes, and snippets.

@j-tap
Last active June 30, 2022 07:15
Show Gist options
  • Save j-tap/8af4bc06b3f8dcd7f88b814c15c4c41c to your computer and use it in GitHub Desktop.
Save j-tap/8af4bc06b3f8dcd7f88b814c15c4c41c to your computer and use it in GitHub Desktop.
# Отменить последний коммит, но сохранить изменения:
$ git reset HEAD~
# Удалить последний коммит и откатить изменения:
$ git reset --hard HEAD~
# Привязать к новому проекту существующий репозиторий
git init
git add .
# если нужно изменить имя ветки (git branch -m main)
git commit -a -m 'start'
git remote add origin {REPO}
git pull --rebase origin main
git push origin main (-f если граф разделён и нужно накатить)
# Если файл попал в индекс и нужно убрать его из индекса (-r рекурсивно):
git rm --cached path/to/file -r
# Если ошибка refusing to merge unrelated histories
git merge --allow-unrelated-histories myfunnybrancy
# Если две ветки раздельно (в начале, когда в созданный репо пуш)
git pull --tags -r
# Очистить удалённый репозиторий и залить туда новые файлы
git checkout --orphan temp
git add -A # Add all files and commit them
git commit -am 'clean'
git branch -D master # Deletes the master branch
git branch -m master # Rename the current branch to master
git push -f origin master # Force push master branch to github
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment