Git Commands
I still use git at the command line when I need some power.
Finding the commit
I use git log -S 'SEARCH' a lot.
I can search for a string through the entire history, across refactors and renames.
The log format
All the options are defined in git-log docs. There are so many ways to output the log for humans or other tools.
If you find an output you want to save, you can add it into your .gitconfig
[pretty]
hashes = format:%H
Using --format=hashes works wherever you can provide it.
Finding lost commits
git reflog is a saviour when you mess up locally.
It has the full history of lost commits.
But it only shows the commit message, not the contents.
Combine commands
Combining git log -S 'SEARCH' $(git reflog --format="%H") works wonders.
main versus master
Working among many orgs means not all have switched to using main, keeping master around.
You can find the current repo setting with git rev-parse --abbrev-ref origin/HEAD.
To use this within aliases though, you must use the shell format:
[alias]
onto = "!git rebase $(git default-branch) --autostash"
Force push
Even when working on an exclusive branch, I always use --force-push-with-lease.
git push --force-with-lease origin HEAD