- Check Impact-of-Change
- Count Lines-of-Code
- Find Commits that Introduced a Change
- Find Large Files in a Repository
- Get Commit-Statistics
- Merge Two Git-Repositories
- Rename the Default Branch from 'master' to 'main'
See how many files (and lines) have changed, between two commits
git diff --shortstat <commit1> <commit2>(from How can I calculate the number of lines changed between two commits in git)
CLOC (Count Lines Of Code) is a Perl-script that does just that.
You can also install it as a package from your Linux-distribution (which is great)
or run it as a docker-container (which is an overkill in most cases).
Run it in a Git-repo, like so:
cloc --vcs git
# or
cloc --git .Count ALL lines-of-code in a repository (limited to a selected set of file-types) -
git ls-files | grep -P "^[^\s]+[.](c|cpp|h|hpp|java|js)$" | xargs cat | wc -lThis example does not handle file-names with spaces, so skipping these files.
(from Count number of lines in a git repository)
# Find commits with a specific RegEx
git log -G '<regex-to-find>'
# ... ignore-case
git log -i -G '<regex-to-find>'
# ... in all branches
git log --all -G '<regex-to-find>'
export SIZE_IN_BYTES=1000000;
git rev-list --objects --all | git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' | grep -v -e 'tag' | awk '$3 > ENVIRON["SIZE_IN_BYTES"]' | sort --numeric-sort --key=3For macOS, make sure you have coreutils:
brew install coreutilsthen run:
export FILE_COUNT=7;
git rev-list --objects --all |
git cat-file --batch-check='%(objecttype) %(objectname) %(objectsize) %(rest)' |
sed -n 's/^blob //p' |
sort --human-numeric-sort --reverse --key=2 |
$(command -v gcut || echo cut) -c 1-12,41- |
$(command -v gnumfmt || echo numfmt) --field=2 --to=iec-i --suffix=B --padding=7 --round=nearest | head -n "$FILE_COUNT"(from How to find/identify large commits in git history?)
git log --raw --all --find-object=<BLOB_ID>(from Which commit has this blob?)
git shortlog --summary --numbered --all
# or
git shortlog --summary --numbered --all --no-merges
# or
git shortlog --summary --numbered --all --no-merges --email(from Git number of commits per author on all branches)
Use this when you have two git-repositories that started the same, and later got diverged.
(If these repositories are completely different than there is not my point in merging them)
To merge branch some-branch from project-a into project-b:
cd path/to/project-a
git checkout some-branch
cd path/to/project-b
git remote add project-a /path/to/project-a
git fetch project-a --tags
git merge project-a/some-branch
# OR:
git merge --allow-unrelated-histories project-a/some-branch
git remote remove project-a(from How do you merge two Git repositories?)
- Change the name of the default branch via the UI of GitLab/GitHub
- Run the following commands on your local copy of that repo:
git branch -m master main git fetch origin git branch -u origin/main main git remote set-head origin -a # Optional: git fetch --prune