Skip to content

Instantly share code, notes, and snippets.

@igniteflow
Last active December 14, 2023 06:31
Show Gist options
  • Save igniteflow/6b662437087087233f33276d110cbe89 to your computer and use it in GitHub Desktop.
Save igniteflow/6b662437087087233f33276d110cbe89 to your computer and use it in GitHub Desktop.
Git commands
# pull changes from a single file inside a commit (useful when hotpatching)
git diff ..<hash> -- <filename> | git apply
# view changes in a file historically
git diff 'HEAD@{3 weeks ago}'..HEAD -- foo/my_module.py
# view commits with patches in this branch only (assuming it was branched from master and is up-to-date)
# useful when reviewing tickets
git log master.. --patch --reverse
# checkout the branch four weeks ago
git checkout 'HEAD@{4 weeks ago}'
# edit the previous commit message (can use `git add ` to add/remove files)
git commit --amend
# move changes from branch
git diff master.. > my.patch
git co new-branch
git apply my.patch
# show unique author names and emails
git log --format="%ae" | sort -u
# pipe changed filenames to black (Python formatter)
git status --porcelain | awk '{print $2}' | xargs black
# create and apply a fix up to previous commit
git commit --fixup <hash>
git rebase -i --autosquash <hash>~1
# list files changed in a commit
git diff-tree --no-commit-id --name-only -r <commit id>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment