0

The question is similar to this one with a small change.

Suppose I have checked out commit B:

  G
   \
E - F - B (*) - A (first commit)
        /      /
   D - C      /
   H - - - - -

So, HEAD is B. I would like to only list those commits to the left of B (including B), or temporally later than B (or including B) that changed a particular file, file1.txt.

There are two subcases -- (1) the commits listed could be only descendants of B so that a later commit whose parent is A that is temporally later than B is not listed (H would not be listed in the example above), (2) the commits listed could be descendants of A on a separate branch yet with a commit date later than B. (H would be listed)

In both subcases, I only want to list commits that affected/changed file1.txt.

The linked to question lists all commits that changed the file including A, which I don't want to be listed.

Tryer
  • 3,580
  • 1
  • 26
  • 49

1 Answers1

1

Subcase 1 is fairly straightforward with --ancestry-path and --all. You could solve Subcase 2 by using a nested command to pass the committer-date of HEAD to --after.

Subcase 1 - All descendents of B (HEAD):

# List HEAD and all of its descendents

git log --graph --oneline --decorate --all \
  --ancestry-path=head head~1..

Subcase 2 - List descendents of the parent of B (HEAD) with a later commit time than B (HEAD):

# List HEAD and descendents of the parent of HEAD.
# Limit by committer-times being after HEAD's.

git log --graph --oneline --decorate --all \
  --ancestry-path head~1.. \
  --after=$(git show -s --format=%ct | awk '{print $1}')
TonyArra
  • 10,607
  • 1
  • 30
  • 46
  • Thank you. The first command results in `fatal: unrecognized argument: --ancestry-path=head` Also, there is no argument in the command that takes in the file name: `file1.txt` in the example of the OP. Version number of git is: git version 2.33.0.windows.2 – Tryer Jan 15 '23 at 06:24
  • @Tryer I didn't include the filename argument from the other answer because it's trivial to add it to the command I gave. I'm just showing you how you would filter the commits by date and ancestry. As for the Windows Git error, I have no way of debugging that. – TonyArra Jan 17 '23 at 14:38