git checkout

Updated: 20 June 2024

Checkout a single file from a specific commit

git checkout <COMMIT> path/to/the/file

Checkout one file from another branch

git checkout grab-from-this-branch -- logout.js

Checkout file(s), as it was at a particular commit

git checkout commit-hash -- my/file another/file2

git search

Updated: 06 July 2023

Search the text (case insensitive) of commit messages in all branches

git log --all -i --grep='text to find'

git config

Updated: 14 May 2024

Username and email

git config --global user.name "John Doe"
git config --global user.email "who@ever.cloud"

Colours

git config --global color.status.updated magenta
git config --global color.status.untracked magenta
git config --global color.diff.old magenta

Set vim as default editor

git config --global core.editor "vim"

Temporarily switch to another ssh private key

git --config "core.sshCommand=ssh -i /home/mruser/.ssh/id_rsa" fetch

git rebase

Updated: 24 May 2023

Rebase onto

git rebase --onto newbase from-commit-after branch-to-move

If required to squash into the first commit of a repository

git rebase --interactive --root

git ignore

Updated: 26 August 2024

Git ignore uses globbing patterns.

Ignore .env file in current directory only and not .env files which might occur further down the directory structure

# .gitignore

/.env

Find which .gitignore entry is responsible for ignoring a particular file

git check-ignore --verbose file/to/check.cs

Show all files being ignored, recursively

find . -type f  | git check-ignore --verbose --stdin

git log

Updated: 26 March 2024

All the refs in refs/

git log --all

All the refs in refs/heads

git log --branches

All the refs in refs/remotes

git log --remotes

All the refs in refs/tags

git log --no-walk --tags

Draw a text-based graphical representation of the commit history

git log --graph --oneline --decorate --all

Refresh git log periodically (every second) with watch utility

watch --color -n 1 git log --graph --oneline --decorate --all --color=always

Show commit which added a file

git log --diff-filter=A -- dotnet.code-workspace

Shows commits that changed a single file, including those commits that occurred before the file was given its present name.

git log --follow builtin/rev-list.c

Find commits by a particular author

git log --author='Chris Taylor'