Skip to content

Instantly share code, notes, and snippets.

@Ravenstine
Last active October 31, 2019 15:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Ravenstine/fea4baa4d21f6ff5e7dafc7836d3258e to your computer and use it in GitHub Desktop.
Save Ravenstine/fea4baa4d21f6ff5e7dafc7836d3258e to your computer and use it in GitHub Desktop.

Git Tricks

Display log in reverse (starting from beginning)

git log --reverse

List all files that have changed from master

git diff --name-only master | tr '\n' ' '

Revert a single commit (without yet creating a new commit)

git revert --no-commit 0766c053

Revert back to a commit (without yet creating a new commit)

git revert --no-commit 0766c053..HEAD

Checkout files from another branch

git checkout --

Checkout and filter file changes from another branch

git diff --name-only | grep "app/" | while read line; do git checkout -- $line; done;

Recover deleted/cleared stashes

git fsck --unreachable | grep commit | cut -d" " -f3 | xargs git log --merges --no-walk --grep=WIP

Then simply git stash apply <commit hash>.

Get current branch name

git branch | grep * | cut -d ' ' -f2

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment