Skip to content

Instantly share code, notes, and snippets.

@tspng
Forked from chrismccoy/gitcheats.txt
Created February 4, 2016 14:24
Show Gist options
  • Select an option

  • Save tspng/e63c44d3ee43a810f612 to your computer and use it in GitHub Desktop.

Select an option

Save tspng/e63c44d3ee43a810f612 to your computer and use it in GitHub Desktop.

Revisions

  1. Chris McCoy revised this gist Dec 23, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # cherry pick range of commits, starting from the tip of 'master', into 'preview' branch
    git rev-list --reverse --topo-order master... | while read rev; do git checkout preview; git cherry-pick $rev || break; done

    # create tracking branches for all remote branches
    git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs;

  2. Chris McCoy revised this gist Dec 23, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,12 @@ alias g='git'
    # create tracking branches for all remote branches
    git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs;

    # git reset newly added files
    for f in `git status | grep new | awk '{print $3}'`; do git reset HEAD $f ; done

    # git reset newly added files
    git reset HEAD -- $(git status | awk '/new file:/{print $3}')

    # pull latest of all submodules
    git submodule foreach git pull origin master

  3. Chris McCoy revised this gist Dec 3, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # create tracking branches for all remote branches
    git branch -a | grep -v HEAD | perl -ne 'chomp($_); s|^\*?\s*||; if (m|(.+)/(.+)| && not $d{$2}) {print qq(git branch --track $2 $1/$2\n)} else {$d{$_}=1}' | csh -xfs;

    # pull latest of all submodules
    git submodule foreach git pull origin master

  4. Chris McCoy revised this gist Dec 3, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # pull latest of all submodules
    git submodule foreach git pull origin master

    # show a git log with offsets relative to HEAD
    git log --oneline | nl -v0 | sed 's/^ \+/&HEAD~/'

  5. Chris McCoy revised this gist Nov 25, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # show a git log with offsets relative to HEAD
    git log --oneline | nl -v0 | sed 's/^ \+/&HEAD~/'

    # list offsets from HEAD with git log
    o=0; git log --oneline | while read l; do printf "%+9s %s\n" "HEAD~${o}" "$l"; o=$(($o+1)); done | less

  6. Chris McCoy revised this gist Nov 25, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # list offsets from HEAD with git log
    o=0; git log --oneline | while read l; do printf "%+9s %s\n" "HEAD~${o}" "$l"; o=$(($o+1)); done | less

    # diff the last 2 commits
    git diff $(git log --pretty=format:%h -2 --reverse | tr "\n" " ")

  7. Chris McCoy revised this gist Jul 22, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # diff the last 2 commits
    git diff $(git log --pretty=format:%h -2 --reverse | tr "\n" " ")

    # reset the last modified time for each file in a git repo to its last commit time
    git ls-files | while read file; do echo $file; touch -d $(git log --date=local -1 --format="@%ct" "$file") "$file"; done

  8. @chrismccoy chrismccoy revised this gist Jul 2, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # reset the last modified time for each file in a git repo to its last commit time
    git ls-files | while read file; do echo $file; touch -d $(git log --date=local -1 --format="@%ct" "$file") "$file"; done

    # get author and email of a commit
    git --no-pager show -s --format='%an <%ae> on %cd' --date=short {commithash}

  9. @chrismccoy chrismccoy revised this gist May 30, 2015. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    alias g='git'

    # get author and email of a commit
    git --no-pager show -s --format='%an <%ae>' {commithash}
    git --no-pager show -s --format='%an <%ae> on %cd' --date=short {commithash}

    # information about an author by giving it's name or email
    git log -i -1 --pretty="format:%an <%ae>\n" --author="$1"
  10. @chrismccoy chrismccoy revised this gist May 30, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # get author and email of a commit
    git --no-pager show -s --format='%an <%ae>' {commithash}

    # information about an author by giving it's name or email
    git log -i -1 --pretty="format:%an <%ae>\n" --author="$1"

  11. Chris McCoy revised this gist Mar 3, 2015. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,12 @@
    # shortform git commands
    alias g='git'

    # information about an author by giving it's name or email
    git log -i -1 --pretty="format:%an <%ae>\n" --author="$1"

    # List all files ever existed
    git log --pretty=format: --name-status $@ | cut -f2- | sort -u

    # commit all changes
    git add -A && git commit -av

  12. Chris McCoy revised this gist Mar 3, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # commit all changes
    git add -A && git commit -av

    # print git commit history
    git log --oneline --decorate | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed 's/([^)]*)\s//g'

  13. Chris McCoy revised this gist Feb 7, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ alias g='git'
    # print git commit history
    git log --oneline --decorate | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed 's/([^)]*)\s//g'

    # print git commit history
    git log --oneline --decorate | tac | nl | tac | sed 's/([^)]*)\s//g'

    # find the date of the first commit in a repo
    git log --pretty=format:'%ad' | tail -1

  14. Chris McCoy revised this gist Feb 7, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # print git commit history
    git log --oneline --decorate | nl | sort -nr | nl | sort -nr | cut --fields=1,3 | sed 's/([^)]*)\s//g'

    # find the date of the first commit in a repo
    git log --pretty=format:'%ad' | tail -1

  15. Chris McCoy revised this gist Feb 5, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # find the date of the first commit in a repo
    git log --pretty=format:'%ad' | tail -1

    # delete all local git branches that have been merged
    git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

  16. Chris McCoy revised this gist Feb 5, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ alias g='git'
    # delete all local git branches that have been merged
    git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

    # delete all git branches except master
    git branch | egrep -v ^master$ | sed 's/^[ *]*//' | sed 's/^/git branch -D /' | bash

    # delete all git branches except master
    git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -D /' | bash

  17. Chris McCoy revised this gist Feb 5, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -7,6 +7,9 @@ git branch --merged | grep -v "\*" | xargs -n 1 git branch -d
    # delete all git branches except master
    git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -D /' | bash

    # delete all git branches except master
    git checkout master; git branch | sed -e '/master/d' -e 's/^/git branch -D /' | bash

    # export current repo to zip archive
    git archive -o "${PWD##*/}.zip" HEAD

  18. Chris McCoy revised this gist Feb 5, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ alias g='git'
    # delete all local git branches that have been merged
    git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

    # delete all git branches except master
    git branch | grep -v "master" | sed 's/^[ *]*//' | sed 's/^/git branch -D /' | bash

    # export current repo to zip archive
    git archive -o "${PWD##*/}.zip" HEAD

  19. Chris McCoy revised this gist Jan 25, 2015. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # delete all local git branches that have been merged
    git branch --merged | grep -v "\*" | xargs -n 1 git branch -d

    # export current repo to zip archive
    git archive -o "${PWD##*/}.zip" HEAD

  20. Chris McCoy revised this gist Nov 26, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ alias g='git'
    # export current repo to zip archive
    git archive -o "${PWD##*/}.zip" HEAD

    # figure out what pull requests are in your current branch (staging) but not yet in master
    git log HEAD...origin/master --pretty=oneline | grep pull

    # remove missing files
    git ls-files -d -z | xargs -0 git update-index --remove

  21. Chris McCoy revised this gist Nov 18, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ alias g='git'
    # export current repo to zip archive
    git archive -o "${PWD##*/}.zip" HEAD

    # remove missing files
    git ls-files -d -z | xargs -0 git update-index --remove

    # list authors of a repo
    git shortlog -sn --all | cut -f2 | cut -f1 -d' '

  22. Chris McCoy revised this gist Nov 18, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ alias g='git'
    # export current repo to zip archive
    git archive -o "${PWD##*/}.zip" HEAD

    # list authors of a repo
    git shortlog -sn --all | cut -f2 | cut -f1 -d' '

    # remove file from repo history
    git filter-branch -f --tree-filter 'rm -rf filename.py' HEAD

  23. Chris McCoy revised this gist Nov 18, 2014. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -2,7 +2,7 @@
    alias g='git'

    # export current repo to zip archive
    git archive HEAD --format zip --output "${PWD##*/}.zip"
    git archive -o "${PWD##*/}.zip" HEAD

    # remove file from repo history
    git filter-branch -f --tree-filter 'rm -rf filename.py' HEAD
  24. Chris McCoy revised this gist Nov 18, 2014. 1 changed file with 0 additions and 3 deletions.
    3 changes: 0 additions & 3 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -340,9 +340,6 @@ git diff -U10|dwdiff --diff-input -c|less -R
    # Better git diff, word delimited and colorized
    git diff -U10 |wdiff --diff-input -a -n -w $'\e[1;91m' -x $'\e[0m' -y $'\e[1;94m' -z $'\e[0m' |less -R

    # extracts 64 bytes of random digits from random lines out of /dev/random sent to stdio
    cat /dev/urandom|od -t x1|awk 'NR > line { pos=int(rand()*15)+2;printf("%s",$pos);line=NR+(rand()*1000);digits = digits+2 } digits == 64 { print("\n");exit }'

    # Count git commits since specific commit
    git log --pretty=oneline b56b83.. | wc -l

  25. Chris McCoy revised this gist Nov 18, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # export current repo to zip archive
    git archive HEAD --format zip --output "${PWD##*/}.zip"

    # remove file from repo history
    git filter-branch -f --tree-filter 'rm -rf filename.py' HEAD

  26. Chris McCoy revised this gist Nov 14, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # remove file from repo history
    git filter-branch -f --tree-filter 'rm -rf filename.py' HEAD

    # list repos by username
    curl "https://api.github.com/users/username/repos?type=owner&sort=updated" -s | sed -En 's|"name": "(.+)",|\1|p' | awk '{print $1}'

  27. Chris McCoy revised this gist Nov 1, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # list repos by username
    curl "https://api.github.com/users/username/repos?type=owner&sort=updated" -s | sed -En 's|"name": "(.+)",|\1|p' | awk '{print $1}'

    # fetch all git remotes for a repo
    git branch -r | awk -F'/' '{print "git fetch "$1,$2}' | xargs -I {} sh -c {}

  28. Chris McCoy revised this gist Oct 31, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,9 @@
    # shortform git commands
    alias g='git'

    # fetch all git remotes for a repo
    git branch -r | awk -F'/' '{print "git fetch "$1,$2}' | xargs -I {} sh -c {}

    # add a tag
    git tag -a 1.2 -m "Version 1.2 Stable"

  29. Chris McCoy revised this gist Oct 15, 2014. 1 changed file with 3 additions and 0 deletions.
    3 changes: 3 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -4,6 +4,9 @@ alias g='git'
    # add a tag
    git tag -a 1.2 -m "Version 1.2 Stable"

    # show which branches are tracking what
    git for-each-ref --format='%(refname:short)' refs/heads/* | while read b; do if r=$(git config --get branch.$b.remote); then m=$(git config --get branch.$b.merge); echo "$b -> $r/${m##*/}"; fi; done

    # push tags
    git push --tags

  30. Chris McCoy revised this gist Sep 8, 2014. 1 changed file with 6 additions and 0 deletions.
    6 changes: 6 additions & 0 deletions gitcheats.txt
    Original file line number Diff line number Diff line change
    @@ -1,6 +1,12 @@
    # shortform git commands
    alias g='git'

    # add a tag
    git tag -a 1.2 -m "Version 1.2 Stable"

    # push tags
    git push --tags

    # download all files from a gist without git
    curl -L https://gist.github.com/username/gistid/download | tar -xvz --strip-components=1