Skip to content

Instantly share code, notes, and snippets.

@causztic
Last active October 26, 2023 06:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save causztic/6773b7d4d48bf9270a4bb372fe03f321 to your computer and use it in GitHub Desktop.
Save causztic/6773b7d4d48bf9270a4bb372fe03f321 to your computer and use it in GitHub Desktop.
List of useful commands as a Rails developer

Here are some commands I use rather frequently.

Git

git rebase --onto new-parent old-parent - Change parent branch of a fork

git remote prune origin - Clean up git remotes

git rebase -i <other-branch> - Dropping, squashing, rewording a list of commits

Gets all merges within a range of dates

Dates must be a ISO format: YYYY-MM-DDTHH:MM:SS

git log --pretty=format:'%aI %H' --first-parent | \ 
awk '$1 >= "<start date>" && $1 <= "<end date>" { print $2 }' | \
git log --pretty=format:'%an|%s' --no-walk --stdin | \
column -t -s '|'

Cherry pick a particular file from a commit to the current branch from here

git show YOURHASH --no-color -- file1.txt file2.txt dir3 dir4 | git apply -3 --index -

Changing git authors for commits

git rebase -i HEAD~n # replace n with a number
# replace commits from pick to edit
git commit --amend --author 'new author name <new author email>' --no-edit
git rebase --continue

Others

lsof -i :8080 - List running processes listening to a certain port (e.g. 8080)

ulimit -n 8192 - When there are not enough file descriptors due to too many open files

docker system prune - Not enough disk space due to Docker shenanigans

Vim

*cgn or cgn to replace a word - repeat the replacement with .

yy 30p - to copy a line and then paste 30 times (the number can be changed accordingly)

Postgres

\x for expanded view - useful for easily viewing records

\pset format wrapped - good for viewing table definitions

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment