code: def _get_n_commits(
      scm: "Git", revs: List[str], num: int
  ) -> List[str]:
      results = []
      for rev in revs:
          if num == 0:
              continue
          results.append(rev)
          n = 1
          while True:
              if num == n:
                  break
              try:
                  head = f"{rev}~{n}"
                  results.append(resolve_rev(scm, head))
              except RevError:
                  break
              n += 1
      return results
  
imports: import os
  from contextlib import contextmanager
  from functools import partial
  from typing import TYPE_CHECKING, Iterator, List, Literal, Mapping, Optional, Union, overload
  from funcy import group_by
  from scmrepo.base import Base
  from scmrepo.git import Git
  from scmrepo.noscm import NoSCM
  from dvc.exceptions import DvcException
  from dvc.progress import Tqdm
label_desc: Use image node_id 8 for calling a global function with example usage: _get_n_commits(scm, revs, num) and returns: results