0

In a Git repository, on the main (or master) branch, I would like to identify the "latest" commit in the topological order, including merge commits, which made any change in a specified directory.

More context:

I have a kind of mono-repo managed on GitHub. Imagine it's like below:

/
|-- file1
|-- file2
|-- subproject1/
|   |-- file1-1
|   `-- file1-2
|-- subproject2/
|   `-- file2-1
`-- subproject3/
    `-- file3-1
  • Assume it's on GitHub
  • Assume any force push is prohibited on the main branch (by restricting on GitHub)
  • Assume the main branch can be updated with the latest commit of :
    • A plain (non-merge) commit by :
      • "Rebase and merge" (whose last commit is a plain commit) from a pull request
      • "Squash and merge" from a pull request
      • A direct fast-forward push (whose last commit is a plain commit) on main
    • A merge commit by :
      • "Merge pull request" from a pull request
      • "Rebase and merge" (whose last commit is a merge commit) from a pull request
      • A direct fast-forward push (whose last commit is a merge commit) on main
  • Under those assumptions, I'd like to identify :
    • the "latest" commit (either a plain or merge commit above) that made any change in a specific directory, ex, subproject1/,
    • in the topological order (not author-date nor commit-date)
    • from HEAD of the current main branch

I looked into these questions and answers below, but not very sure...

Does anyone have ideas?

Dai MIKURUBE
  • 125
  • 1
  • 1
  • 13
  • Use `git log` or `git rev-list` with `--topo-order` and the path name of the directory in question. Add `--full-history` to avoid history pruning if you want to inspect commits that *didn't* contribute to the *current* state (where "current" is defined as whatever the tree looks like in your start point for your topo-order walk). – torek Jul 01 '22 at 09:53
  • No, it does not include merge commits. That's the point of my question. – Dai MIKURUBE Jul 02 '22 at 01:11
  • 1
    The fact that the output does not list the merge commits themselves is the key to your question. Add `-m` to make log and rev-list inspect the diffs from each merge to each parent, which will make the merge commits participate in the file-diff "do/don't print this commit" selection test. (I missed this point in my initial scan of your question.) – torek Jul 02 '22 at 06:00
  • Thanks. Yeah, `-m` added some merge commits, but they were too many, then I made this question. Okay, I'll have to inspect every merge commit to check whether it's to be included or not... – Dai MIKURUBE Jul 04 '22 at 07:17

1 Answers1

0

I think you are looking for a plain : git log -1 -- path/to/directory

LeGEC
  • 46,477
  • 5
  • 57
  • 104