git在什么时候完成执行操作?

I have an utility in Go that runs commits checkouts via os/exec and then does some operations on files from the commit.

I suspect that at the moment this command returns its return code:

_, err := exec.Command("git", "-C", sourceDir, "checkout", hash).Output()

The whole file tree is up to date in the folder and I can do whatever I want with the files, without the need to wait for some operations to finish in background.

What if it's a very large repository, where one commit differs much from another one and it takes time to sync deleted/added/modified files when switching from one commit to another?

Can I run my operations right after git checkout returns 0?

git checkout does not exit until the checkout is completed (or has failed).

Comments about auto-gc in the background are not particularly relevant here, since auto-gc is not related to whether the checkout has finished. For that matter, git checkout does not run git gc --auto: there is no point since git checkout does not create new Git objects. A reasonably current list of things that do invoke git gc --auto (as of about 2.18) is:

  • git am
  • git commit
  • git fetch
  • git merge
  • git receive-pack (servers)
  • git rebase