Is it safe if more git commands are run on the same repo in parallel?

前端 未结 2 373
攒了一身酷
攒了一身酷 2020-12-29 04:11

I am interested if it is safe to run things like git push and git commit in parallel (for example in cron jobs, jenkins jobs etc.). Is there some l

相关标签:
2条回答
  • 2020-12-29 05:05

    In theory, there could be a rare case of race condition for the git commit part, where the HEAD file is not available.
    That was silent before Git 2.15.x/2.16 (Q1 2018). It won't be silent anymore.

    See commit c26de08 (20 Oct 2017) by Andrey Okoshkin (``).
    (Merged by Junio C Hamano -- gitster -- in commit 4a1638c, 06 Nov 2017)

    commit: check result of resolve_ref_unsafe

    Add check of the resolved HEAD reference while printing of a commit summary.
    resolve_ref_unsafe() may return NULL pointer if underlying calls of lstat() or open() fail in files_read_raw_ref().
    Such situation can be caused by race: file becomes inaccessible to this moment.

    The message becomes:

    if (!head)
        die_errno(_("unable to resolve HEAD after creating commit"));
    
    0 讨论(0)
  • 2020-12-29 05:06

    Yes. Git works by writing references in a manner that allows for this. If you are doing a commit at the same time as a push, push will only go from the references down to the objects they contain. If the commit finishes and updates the branch reference on time, it will get pushed. If it doesn't, the old reference will be pushed. You won't get "half a commit" pushed up.

    All files are written in a manner that implicitly preserves referential integrity for any pointers. The last file written will be the reference that already has all it's dependencies there.

    0 讨论(0)
提交回复
热议问题