2022-10-04
Git is one of those tools that I have been using for the past 4-5 years on a daily basis, very very good tool. Below I share some git commands and aliases ...etc, that I've collected over the years.
git log
?-p
option makes it show the diff along with the commit message, very good for searching in e.g. less (or whatever pager you use); for what --pickaxe-all does, have a look at the documentation
git cot blahbleh
Custom Git Commands:
Some other commands are too big for an alias, so it's easier to use a git script, basically create a shell script somewhere in your PATH, make it executable and name it git-command_name (where command_name is the name of the command you want use e.g. git-history, you can then use git history
like any other git command).
#!/usr/bin/bash git reflog "$@" | grep "checkout:" | perl -p -e 's@.+checkout: moving from ([^ ]+).+@$1@' | grep -v master | uniq | head -n 20Prints a list of the branch names that you have checked out / switched to/from, in chronological order; useful when you have many local branches and can't remember the name of one of the recent ones you've been working on. (I omit "master", because I don't have trouble remembering the name of that one).
#!/usr/bin/bash git diff --name-only --diff-filter=U | xargs git addWhen doing an interactive rebase and after resolving conflicts, you have to `git add` the files that had conflicts, this command does exactly that.
#!/usr/bin/bash newName=$(git branch --show-current)-2 git branch --copy $newNameCreates a copy of the current branch, named current-branch-name-2, basically creating a backup copy in case whatever changes I am about to attempt doing don't work out.