Skip to content

Instantly share code, notes, and snippets.

@denji
Forked from jeremypage/git-cheatsheet.md
Last active December 1, 2023 00:50
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 denji/c2ac759ba4569c22c088c17ebb2f3a79 to your computer and use it in GitHub Desktop.
Save denji/c2ac759ba4569c22c088c17ebb2f3a79 to your computer and use it in GitHub Desktop.
Git cheatsheet

Git cheatsheet

Find all instances of text in all commits

git grep "text to look for" $(git rev-list --all)

List commit messages since given commit

git log --pretty=format:%s HASH..HEAD

Config repository master branch to only accept non-fast forward commits

git config branch.master.mergeoptions  "--no-ff"

Hint: Don't do this on your local working copy, or everytime you do a 'pull' from origin it will create yet another explicit commit (as opposed to a simple fast-forward).

Move branch to master without checking out

git branch -f <BRANCH_TO_MOVE> master

Speed up Git in Windows

(From http://stackoverflow.com/a/24045966)

You can significantly speed up git on Windows by running three commands to set some config options:

git config --global feature.manyFiles true
git config --global core.preloadindex true
git config --global core.fscache true
git config --global gc.auto 256

Notes:

  • core.preloadindex does filesystem operations in parallel to hide latency and will be enabled by default in future versions of git on all platforms (update: enabled in v2.1)

  • core.fscache fixes UAC issues (don't need to run git as admin)

  • gc.auto minimizes the number of files in .git

Show all changed files between two Git commits

git diff --name-status SHA1 SHA2

Find largest files in repo

Saves results to text file bigtosmall.txt

(From http://naleid.com/blog/2012/01/17/finding-and-purging-big-files-from-git-history)

git rev-list --objects --all | sort -k 2 > allfileshas.txt
git gc && git verify-pack -v .git/objects/pack/pack-*.idx | egrep "^\w+ blob\W+[0-9]+ [0-9]+ [0-9]+$" | sort -k 3 -n -r > bigobjects.txt
for SHA in `cut -f 1 -d\  < bigobjects.txt`; do
echo $(grep $SHA bigobjects.txt) $(grep $SHA allfileshas.txt) | awk '{print $1,$3,$7}' >> bigtosmall.txt
done;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment