Cheats
git
common commands
git log-short 10
git log -10
git log (commit)
git show (commit)
git show (commit):(path/file)
git merge (branch.to.merge.from)
git diff branch1 branch2 --name-only
git diff HEAD^^ HEAD
git diff HEAD~1 HEAD
git pull (remote-name)
git fetch (remote-name)
git checkout (branch-name)
git cherry-pick (commit)
aliases
alias gitlog="git log-short 30"
alias gcp="git cherry-pick"
squash
Compress multiple commits into one commit
Before
(master)v1-->v2-->v3-->v4
After
(master)v1-->v4
All changes in v2, v3 and v4 from Before are compressed into v4 in After.
To do this Squash operation:
1) git rebase -i (v1)
2) pick v2, squash (s) v3 and v4, save
3) comment out the comment to remove, save
git merge
Merge copies all feature branch changes to another branch.
(comment from 2024-11-30: I don't remember doing this at work at all.)
Before
(master)v1-->v2
\
\(br)-->b1-->b2
Git merge moves changes b1 and b2 from branch br to the master branch.
After
(master)v1-->v2-->b1-->b2
\
\(br)-->b1-->b2
git rebase
(comment from 2024-11-30: I don't remember doing this at work at all.)
Before
(master)v1-->v2-->v3
\
\(br)-->b1-->b2
After
(master)v1-->v2-->v3
\
\(br)-->b1-->b2
io
fd = file descriptor
fd 0 = stdin
fd 1 = stdout
fd 2 = stderr
redirect stdout to file: command > x
same as: command 1> x
redirect stderr to file: command 2> x
redirect stdout to x, stderr to y: command 1> x 2> y
redirect stderr and stdout to x: command &> x
same as: command 2>&1 > x
find
find . -name "pattern" # find any objects with a name pattern
find . -name "pattern" -type f # find any files with a name pattern
find . -mtime -1 # find any objects modified within the past day
find . -name "regex_abc" -type f -exec grep -nH regex_xyz {} \;
# find any file with regex_abc whose contents contain regex_xyz
journalctl
journalctl -u (name) -n (last-n-lines) -S (since) -U (until)
-u (name) unit name
-f follow
-n show last 10 entries
-S --since (datetime)
-U --until (datetime)
Datetime options include:
"2022-01-01 09:00:00"
"2022-01-01"
09:00
today
yesterday
"1 hour ago"
"10 minutes ago"
vi
Finding things
f{c} find the next instance of character
F{c} find the previous instance of character
/{pattern} find the next instance of pattern
?{pattern} find the previous instance of pattern
* find the next instance of word under cursor
n after find, go to the next instance
N after find, go to the previous instance
Replacing things
:s/old/new/g replace old with new only on current line
:n,m s/old/new/g replace old with new only on lines n to m
:%s/old/new/g replace old with new globally
%s is special symbol in ed for all rows in file
Vital ops
u undo last sequence of change
Buffers
:e select a file to edit from local folder
:ls list loaded files in buffers
:bn buffer next
:bp buffer previous
:bdelete n buffer delete n
Windows
Ctrl-w s split horizontal window
Ctrl-w v split vertical window
Ctrl-w h/j/k/l window jump- up, down, left, right
Ctrl-w Ctrl-w window cycle
Ctrl-w c close window
Ctrl-w = resize window sizes all equal
Ctrl-w o return to only One window
Visual blocks
v select block by character
V select block by line
Ctrl-v select block
Moving around
$ jump to end of line
dw delete word forward
daw delete a word
dd delete line
Reformatting
:set textwidth=65
v
gq
Bookmarks
m(c) mark position with character c
'(c) jump back to position c
Macros
q(r) record a macro to register r
@(r) playback macro r
n@(r) playback macro r n number of times
Markdown
To turn off markdown marking _ as an error:
add these lines into:
/.vim/after/syntax/markdown.vim
syn match markdownError "\w\@<=\w\@="
syn match markdownIgnore "\$x_i\$"
ssh
ssh-keygen
ssh-add -l
ssh-add (file containing private key)
ssh -T git@bitbucket.org
mounting
sudo fdisk -l
sudo ntfsfix -d /dev/sdb1 // clear dirty flag
photos
mogrify -mattecolor white -frame 20x20 *jpg