Git cheatsheet ============== ## Find all instances of text in all commits ## ```sh git grep "text to look for" $(git rev-list --all) ``` ## List commit messages since given commit ## ```sh git log --pretty=format:%s HASH..HEAD ``` ## Config repository master branch to only accept non-fast forward commits ## ```sh 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 ## ```sh git branch -f 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: ```sh 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 ## ```sh 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) ```sh git rev-list --objects --all | sort -k 2 > allfileshas.txt ``` ```sh 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 ``` ```sh 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; ```