Skip to content

Instantly share code, notes, and snippets.

@sayham-sjb
Last active March 15, 2022 03:05
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save sayham-sjb/5fa76680721c28be2c3905ea1cf2de87 to your computer and use it in GitHub Desktop.
Save sayham-sjb/5fa76680721c28be2c3905ea1cf2de87 to your computer and use it in GitHub Desktop.
Git #git
  • List all modified file names

    • git whatchanged --since '12/01/2016' --oneline --name-only --pretty=format: | sort | uniq
    • git log --since="4 day ago" --name-only --pretty=format: | sort -u
    • git whatchanged --since '12/01/2016' --until '12/06/2016' --oneline --name-only --pretty=format: | sort | uniq
  • Stash

    • git stash
    • git stash list (Get all stash(s))
    • git stash pop (Reapply stash and remove)
    • git stash apply (Reapply stash and keep copy)
    • git stash pop stash@{0} (Reapply specific stash)
    • git stash show (Find summary of stash)
    • git stash show -p (Find full diff)
    • git stash drop stash@{0} (Delete specific stash)
    • Git stash clear (Delete all stash(s))
  • Get a list of git branches, ordered by most recent commit

    • git branch -av
    • git branch -v
    • git branch -vv
    • git for-each-ref --sort='-authordate:iso8601' --format=' %(authordate:relative)%09%(refname:short)' refs/heads
    • git for-each-ref --sort=committerdate refs/heads/ --format='%(authordate:short) %(color:red)%(objectname:short) %(color:yellow)%(refname:short)%(color:reset) (%(color:green)%(committerdate:relative)%(color:reset))'
    • git for-each-ref --sort=-committerdate refs/heads/ #DESC
    • git for-each-ref --sort=committerdate refs/heads/ #ASC
    • git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:red)%(refname:short)%(color:reset) - %(color:blue)%(objectname:short)%(color:reset) - %(contents:subject) -[%(color:cyan)%(authorname)%(color:reset)] (%(color:green)%(committerdate:relative) | %(authordate:short) %(color:reset))'
    • git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:red)%(refname:short)%(color:reset) - %(color:blue)%(objectname:short)%(color:reset) - %(contents:subject) -[%(color:cyan)%(authorname)%(color:reset) | %(color:green)%(committerdate)%(color:reset) | %(color:green)%(committerdate:relative)%(color:reset)]'
    • git for-each-ref --sort=committerdate refs/heads/ --format='%(HEAD) %(color:red)%(refname:short)%(color:reset) %(color:blue)%(objectname:short)%(color:reset) %(contents:subject) [%(color:cyan)%(authorname)%(color:reset) | %(color:green)%(committerdate)%(color:reset) | %(color:green)%(committerdate:relative)%(color:reset)]'
  • Get all the recently checked out branches

    • git reflog | egrep -io "moving from ([^[:space:]]+)" | awk '{ print $3 }' | head -n5
  • Showing branch hierarchy at the command line

    • git log --all --graph --decorate --oneline --simplify-by-decoration
    • git show-branch
    • git show-branch --all
    • git log --graph --simplify-by-decoration --pretty=format:'%d' --all
    • git log --graph --oneline --decorate --all
    • git log --oneline --abbrev-commit --all --graph
    • git log --oneline --abbrev-commit --all --graph --decorate
  • Run a command in time interval

    • while true; do ls; sleep 2; done [while true; do <your_command>; sleep <interval_in_seconds>; done]
  • New

  • New

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