Skip to content

Instantly share code, notes, and snippets.

@achesco
Last active November 6, 2017 09:59
Show Gist options
  • Save achesco/999cdce798c2bbee0ef2fe2d0f3bcb72 to your computer and use it in GitHub Desktop.
Save achesco/999cdce798c2bbee0ef2fe2d0f3bcb72 to your computer and use it in GitHub Desktop.
git-snippets.sh
# GitFlow
git checkout develop && git checkout -b _feature-branch_
git reset --soft _commit-id_
git commit [-a] [-—amend] [--no-edit]
git fetch origin
git pull --rebase origin develop
git push origin _branch-name_ [-f]
# Reset one commit back
git reset --soft HEAD~1
# Unstage files from index
git reset HEAD <file>
# 1. Remove untracked files from the working tree
# -n - dry run - only preview results
# -f - force (clean.requireForce)
# -X - remove ignored files
# -x - remove ignored and non-ignored files
# -d - remove directories
git clean -n -f[xXd]
# 2. Run if preview doesn’t scare you
git clean -f[xXd]
# Remove odd unstated files changes
# 1. Stash unstated modified / new files
git stash save -—keep-index
# 2. Remove stash then
git stash drop
# Contents of the index
git ls-files --abbrev --stage
# Differences between working tree and the index (not current commit)
git diff
# Differences between the index and the current commit
git diff --staged
# Cписок обновленных файлов начиная с коммита
tar czf changes.tgz `git diff --name-only _from-commit-id_ _to-commit-id_`
# или
git diff --name-only _from-commit-id_ _to-commit-id_ | xargs tar -czf changes.tgz
# В корне проекта в результате получаем архив со всеми файлами разложенных
# по папочкам в соотвествии с иерархией проекта.
# Squashing commits
# http://gitready.com/advanced/2009/02/10/squashing-commits-with-rebase.html
# тут еще про Chery Pick, как объеденить несколько не последовательных коммитов
# http://clock.co.uk/tech-blogs/deleting-a-git-commit
# Удалить последний коммит после пуша
git reset --hard HEAD~1
# Delete all branches merged to ‘develop'
git checkout develop && git fetch --prune && git branch --merged | grep -v develop | xargs git branch -d
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment