pre-push script

vim .git/hooks/pre-push
#!/bin/bash

echo "Running pre-push checks..."
make ci
chmod +x .git/hooks/pre-push

Download specific dir from a GitHub repo

apt install subversion

IMPORTANT for master replace tree/master or blob/master part of URL with trunk. Trust this is

https://github.com/lodash/lodash/tree/master/test ➜ https://github.com/lodash/lodash/trunk/test

svn checkout https://github.com/friendlyantz/repo-name/trunk/dir/
# or specific file
svn cat https://github.com/friendlyantz/repo-name/trunk/dir/file.name > file.name
  • If you’re interested in foo branch, use branches/foo instead. The full path looks like branches/foo/foldername
  • Protip: You can use svn ls to see available tags and branches before downloading if you wish

GitIgnore / Stop tracking

Completely remove file from git tracking

echo '*.bin' >> .gitignore
git rm --cached path/to/your/file.bin

Or just

Stop tracking changes, but keep it in git

git update-index --assume-unchanged path/to/your/file.bin

Cherry-pick

cherry-pick commit without commiting

git cherry-pick -n <HASH>

Commit message template

vi .git/.gitmessage

git config commit.template .git/.gitmessage

Fixup commit

  1. add new commit with fixes. any message
  2. rebase
    git rebase -i HEAD~6 #or main
    
  3. move fixup after crooked commit and flag it with f

Restore deleted file

git log -- <filename>

git checkout <deletion commit hash>~1 -- <filename>

___

git show --name-only {commit}

Hard reset (please avoid at all costs)

First, run a fetch to update all origin/<branch> refs to latest: git fetch --all Backup your current branch: git checkout -b backup-master Then, you have two options: git reset –hard origin/master OR If you are on some other branch: `git reset –hard origin/

Churn factor

git log --format=oneline -- app/models/user.rb | wc -l

 get the top-10 files according to churn:

find app/models -name "*.rb" | while read file; do echo $file `git log --format=oneline -- $file | wc -l`; done | sort -k 2 -nr | head

specific authors

 git log --author="friendly\|SomeName"

specific dir

git log --name-only --since="YYYY-MM-DD" --until="YYYY-MM-DD" path/to/dit/or_file

log/blame specific lines

git log -L 1,19:./index.md

git blame -L 1,9 no_space/path_to/file

without whitespace -w

git blame -w -L 14,24 README.md

without copied in the same commign -C, commint and parent -C -C, all -C -C -C

IncludeIf - various configs for work and personal

[includIf "gitdir:~/work/"]
    path = ~/work/.gitconfig
[includeIf "gitdir:~/personal/"]
    path = ~/personal/.gitconfig
git config --global user.email

Search

git log -S filews_watcher -p

word based diff

git diff --word-diff

Enable ReReRe by default

git config --global rerere.enabled true

Maintenance - do it now!!!




Leave a comment