EN VI

Bash - get a list of files with N commits from git?

2024-03-14 11:00:06
How to Bash - get a list of files with N commits from git

I am trying to get a list of files in a git repository that have only a single commit. So from the subject N would be 1.

I have a bash script which can perform the job. However, I would like to do this with just git commands. I have access to git filter-repo and I can't find a way in that documentation either.

This is part of an svn to git migration and it would be nice to get this information without the find since the first repository created does not have files until it is clone'd once.

The bash script that works is:

export OFS=$IFS; export IFS=$'\n'; total=0; for i in $(find . -type f -not -path "./.git/*"); do sum=`git log --graph --oneline --reflog --all --pretty='format:%C(auto)%h%d (%an, %ar)' $I | wc -l ; if [[ $sum -gt 0 ]]; then let "total++"; echo $i" "$sum; fi; done; echo "total files = $total"

The bash one-liner can be shortened but that isn't what I'm trying to figure out. I'm attempting to find a way to get similar information with git. Namely, I would like a programmatic git solution to get the list of files with N commits. In my use N is 1.

Solution:

These build-with-just-one-tool conceits might make fun puzzles, but the fact is Git's one tool in a very capable toolbox.

git log --pretty= --name-status | awk -F$'\t' '!seen[$2]++ && $1=="A"'

will find all files that haven't been touched since being added.

Answer

Login


Forgot Your Password?

Create Account


Lost your password? Please enter your email address. You will receive a link to create a new password.

Reset Password

Back to login