Git

Troubleshooting

Verbose Git SSH Commands

GIT_SSH_COMMAND="ssh -v" git push
 
GIT_TRACE=1 git push

Configuration

Auto CRLF

# automatically convert between CRLF and LF
# - true:  converts on git add/checkout
# - input: converts on git add
# - false: converts neither
git config --global core.autocrlf=false

Long filepaths

# allows for filepaths on windows longer than 260 characters
git config --global core.longpaths true

Git Log

Search Git History

# search for commits where SEARCH was changed
git log -S [SEARCH]
# view diffs
git log -S [SEARCH] -p

Show git commits done today

git log --oneline --graph --after="$(date -u +"%Y-%m-%d") 00:00"

Example:

* 41266d2 feat(vim): add mappings for quick dot-files editing
* 77af3d1 fix(vim): fix autocompletion with tab not working in vimwiki files
* 06e5237 feat(vim): show converted pdf when compiling from markdown
* cb80738 fix(vim): filename with spaces not passed as single argument to shell scripts
* 5ac005c feat(taskwarrior): add dot-files

Trace Line Evolution

Useful to show the history of a function in a given file. source: Prioritizing Technical Debt as if Time and Money Matters

$function="menu"
$file="./scripts/.local/bin/i3-profile.sh"
git log -L :$function:$file

Other Commands

Create branch from specific commit

git branch feature/login HASH

Show character changes in Diff

git show ac9ffd9 --color-words=.

Git Reflog

This is really powerful.

After a git reset --hard HEAD^^, see any dangling commits with git reflog. Then create a branch pointing to one of those commits with git branch backup [SHA]. Then just git merge backup to merge these commits into the current one.

Ignore changes to versioned file

# version initial 'file'
echo "Changes" >> file
git add file
git commit -m "init commit"
# ignore future changes for 'file'
echo "file" >> .gitignore
# tell git to ignore changes
git update-index --skip-worktree ignored file

Restore deleted file

# find commmit where file was deleted
git log --diff-filter=D -- FILE
# restore file before deletion
git checkout COMMIT_SHA^ -- FILE