Skip to content

Instantly share code, notes, and snippets.

@swimtver
Last active January 17, 2018 12:49
Show Gist options
  • Save swimtver/eded551cba652f792fed to your computer and use it in GitHub Desktop.
Save swimtver/eded551cba652f792fed to your computer and use it in GitHub Desktop.
git cheatsheet
1. discard unstaged changes
git clean -df // clean removes all untracked files
git checkout -- . // checkout clears all unstaged changes
git checkout path/to/file // clear specific file
2. log последние 3 коммита
git log --pretty=format:"%h %s" HEAD~3..HEAD
3. Объединить 2 коммита
git rebase -i HEAD~2
откроется окно с коммандами. к последнему коммиту приписать squash вместо pick. Сохранить.Закрыть.
Откроется ещё одно окно. попросят ввести message для коммита. Сохранить.Закрыть.
4. Удаление веток
git branch -d the_local_branch // локальная
git push origin :the_remote_branch // удалённая
git fetch -[p]rune // полезно делать когда кто-то удялял remote branches
// remove any remote-tracking branches which no longer exist on the remote
5. Закоммитить в предыдущий коммит
git commit -a --amend
6. Откатить до коммита
git reset --hard <sha1-commit-id>
git clean -fd
git commit -m "Revert to <sha1-commit-id>"
git push origin HEAD --force
7. fix .gitignore (commit everything you changed before you do this)
git rm . -r --cached
git add .
git commit -m "fixed untracked files"
8. reset branch to remote state
git fetch origin
git reset --hard origin/master
9. git stash
git stash apply
git stash drop
git stash pop (apply + drop)
git stash clear
10. tagging
git tag v1.0
git push origin v1.0
11. git fixup COMMIT // https://blog.filippo.io/git-fixup-amending-an-older-commit/
[alias]
fixup = "!f() { TARGET=$(git rev-parse "$1"); git commit --fixup=$TARGET ${@:2} && EDITOR=true git rebase -i --autostash --autosquash $TARGET^; }; f"
12. git describe // https://git-scm.com/docs/git-describe https://habrahabr.ru/post/140835/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment