## Unstage files
git restore --staged .
## Change last commit message (1st one will open editor)
git commit --amend
git commit --amend -m "New commit message"
## Add another repo in existing
git remote add <remote name/alias> <clone_url>
# Push/pull from another repo (after add)
git pull <remote name/alias> <remote_branch>
## Stage deleted files only
# https://git-scm.com/docs/git-ls-files
git ls-files --deleted | xargs git add --all
# Stage delete files of an specific directory (lib/foo)
git ls-files --deleted -- lib/foo | xargs git add --all
## Initial commit
git rev-list --max-parents=0 HEAD
## Latest tag
git describe --tags --abbrev=0
## Parsable changelog (version to version)
# here 3.22 & HEAD indicates version/tag
git --no-pager log --no-merges 3.22..HEAD --pretty=">>%h|%ce|%ct|%s|%b|%N" --shortstat
## Get number of changes between 2 commit
git diff --shortstat dfd7386d1a808f5852fb33aa7aa13e78a6c3b561 HEAD
## Get list of changed files between commits/branches
git --no-pager diff HEAD..master --name-only # e.g. getting list of changes between current head & master
## Force LF instead of CRLF
git config --global core.autocrlf false
git config --global core.eol lf
## Prune
git remote update origin --prune
git fetch -p && for branch in $(git for-each-ref --format '%(refname) %(upstream:track)' refs/heads | awk '$2 == "[gone]" {sub("refs/heads/", "", $1); print $1}'); do git branch -D $branch; done
# need python & pip installed in your OS, then run following
pip install git-fame
# Set global alias (windows)
git config --global alias.fame "!python -m gitfame"
# Set global alias (Linux/Mac; may not need)
# You may have to set python3 instead of python
git config --global alias.fame '!python -m gitfame'
# Restart terminal
# Get Normal Counter on Surviving code (low accuracy)
git fame -e --enum
# Get Deep Counter on Surviving code (intra-file & inter-file modifier detector, file system independent) more calculation time
# You can combine --branch=<branch_name> (default is HEAD) for branch/tag specific info
git fame -ewMC --enum
# Check `git fame -h` command for command details
You can add CODEOWNERS
with this library as well
# bash syntax function for current directory git repository
owners(){
for f in $(git ls-files); do
# filename
echo -n "$f "
# author emails if loc distribution >= 30%
git fame -esnwMC --incl "$f" | tr '/' '|' \
| awk -F '|' '(NR>6 && $6>=30) {print $2}' \
| xargs echo
done
}
# print to screen and file
owners | tee .github/CODEOWNERS
# same but with `tqdm` progress for large repos
owners \
| tqdm --total $(git ls-files | wc -l) \
--unit file --desc "Generating CODEOWNERS" \
> .github/CODEOWNERS
# need python & pip installed in your OS, then run following
# if windows
winget install ffmpeg
python -m pip install manim
python -m pip install gitpython
python -m pip install git-story
# if linux
sudo apt install build-essential python3-dev libcairo2-dev libpango1.0-dev ffmpeg
pip install manim
pip install gitpython
pip3 install git-story
# Restart terminal
# Generate with default config
git-story
# To customize the options check
git-story -h