1

I suspect I may have a commit on a branch of mine - after the branch point from a master branch - which is empty. I want to find this commit (or maybe more than one?) and have a look at its commit message

Now, I could of course examine all commits from the branch point one by one and check whether they're empty or not. I could probably even write a shell script which takes the number of commits to look back and keeps executing

git diff HEAD^{n+1}  HEAD^^^^...lots of ^{n}

and checking the number of output lines, and using that to get the commit IDs. But - I was hoping there was some either way to better automate this. I know that there's a git filter-branch command which could remove empty commits, but I first want to know whether I had any and where they are. Also I don't want to go all the way back to the initial commit.

einpoklum
  • 118,144
  • 57
  • 340
  • 684
  • 1
    Does this answer your question? [How can I find empty git commits?](https://stackoverflow.com/questions/26683792/how-can-i-find-empty-git-commits) – Serge Feb 23 '20 at 23:03
  • @Serge: I've tweaked my question to be different than that one. Also note I don't want to go all the way back to the initial commit. – einpoklum Feb 23 '20 at 23:06
  • 1
    you can easily modify the scripts in the answer to use revieion ranges. – Serge Feb 24 '20 at 01:23

1 Answers1

0

You can use:

git log --stat

which will give you, for every commit listing, a line such as:

7 files changed, 55 insertions(+), 75 deletions(-)

then you can search for 0 files changed. Now, that isn't full automation, but since you said you wanted to have a look at which commits these are, that's a good way to do it.

You could also use something like

sed -r '/^commit [a-z]{8,}/,/^[1-9] files changed/d'

on the log output, to remove the entries for commits with changes. (Caveat: haven't tested this sed command.)

einpoklum
  • 118,144
  • 57
  • 340
  • 684