简体   繁体   English

并发git拉到相同的本地存储库

[英]concurrent git pulls to same local repository

I've been tasked with maintaining a Jenkins server with jobs that basically check out some code and build it. 我的任务是维护Jenkins服务器,其工作基本上可以检出一些代码并进行构建。 Currently they do a git clone using the "--depth 1" and "-b {branch}" options to get a specific code branch as quickly as possible. 目前,他们使用“ --depth 1”和“ -b {branch}”选项进行git克隆,以尽快获得特定的代码分支。 But this is still wasteful since a fresh copy is being checked out (over the network) every time a job executes, even if there are very few (if any) changes. 但这仍然很浪费,因为每次执行作业时都会(通过网络)检出新副本,即使更改很少(如果有)也是如此。

Instead, what I'd like to do is have a shared local repo on the build machine that's a clone of our remote repo. 相反,我想做的是在构建计算机上有一个共享的本地存储库,它是我们的远程存储库的克隆。 Each job would do a "git pull" on a specific branch to bring in any changes from the remote repo, then copy the source tree from the repo to its Jenkins workspace before starting the build. 每个作业都会在特定分支上执行“ git pull”操作,以从远程存储库引入任何更改,然后在开始构建之前将源树从该存储库复制到其Jenkins工作区。

Is this a bad idea? 这是一个坏主意吗?

What concerns me is the possibility that different jobs targeting the same code branch will be run simultaneously, which could result in concurrent "git pull" requests. 我担心的是,针对同一代码分支的不同作业可能同时运行,这可能导致并发的“ git pull”请求。

Could this result in corruption of Git's meta-data? 这会导致Git的元数据损坏吗?

Is one of the concurrent pulls likely to fail due to locking issues? 并发请求之一是否可能由于锁定问题而失败?

The shared local repo would never have any changes committed to it and nothing would ever be pushed from it to the remote repo. 共享的本地存储库将永远不会进行任何更改,也不会将任何内容推送到远程存储库。 It would be "pull only", so to speak. 可以这么说,它将是“仅拉”式的。 All the pulls would come from the same user, so there shouldn't be any file permission issues. 所有拉取将来自同一用户,因此不应有任何文件许可问题。

Some googling turned up this discussion from 4 years ago, but it doesn't seem conclusive: 从4年前开始,有人在Google上进行了讨论,但似乎没有定论:

http://git.661346.n2.nabble.com/concurrent-fetches-to-update-same-mirror-td5893458.html http://git.661346.n2.nabble.com/concurrent-fetches-to-update-same-mirror-td5893458.html

Is this a bad idea? 这是一个坏主意吗?
Can think of a following scenario. 可以想到以下情形。
Assuming Job1 did a git pull and checked out the latest code and started copying from the local git repository to the workspace. 假设Job1进行了git pull并签出了最新代码,并开始从本地git存储库复制到工作区。 At this particular moment, Job2 did a git pull and few of the files got copied when the copy process was still going on (For a large repository, i believe it could be possible). 在此特定时刻,Job2进行了git pull,并且在复制过程仍在进行时,很少文件被复制(对于大型存储库,我相信这是可能的)。 In such cases, you might have files from both the checkouts, which is not something you want. 在这种情况下,您可能会同时拥有两个检出的文件,这不是您想要的。 Please correct me, if am wrong in this particular scenario. 如果在此特定情况下有误,请纠正我。

Though not part of the original question, adding the below as it might be useful to others. 尽管不是原始问题的一部分,但添加以下内容可能对其他人很有用。
Since, you've mentioned clearly that you are not going to commit anything back to the git, you don't encounter the race condition. 因为,您已经明确提到您不会将任何内容提交回git,所以您不会遇到竞争条件。

"hint: Updates were rejected because the tip of your current branch is behind “提示:由于您当前分支的提示不在后面,因此更新被拒绝
hint: its remote counterpart. 提示:它的远程副本。 Merge the remote changes (eg 'git pull') 合并远程更改(例如“ git pull”)
hint: before pushing again. 提示:再次推送之前。
hint: See the 'Note about fast-forwards' in 'git push --help' for details. 提示:有关详细信息,请参见“ git push --help”中的“关于快进的注意事项”。
child exited with value 1 - " 子项退出,值1-“

You'll encounter this error if your job, after the execution, checks in a few files into git (Update version number, changelog etc...). 如果作业执行后将几个文件检入git(更新版本号,变更日志等),则会遇到此错误。 This error occurs when you have checked out a specific revision from git and there has been a fresh check-in in the same branch of the repository and the current job tries to commit the updated files and it finds that the git is not in the same version as it was when it checked out. 当您从git中签出特定修订版,并且在存储库的同一分支中进行了新签入,并且当前作业尝试提交更新的文件,并且发现git不在同一版本中时,会发生此错误签出时的版本。

  • If you are not committing anything back to git, its worth giving it a try as you can save space / job execution time by avoiding multiple pull. 如果您没有将任何内容提交回git,那么值得尝试一下,因为通过避免多次拉动可以节省空间/作业执行时间。
  • If you commit anything back, its not a good idea to share a single git repository across multiple jobs. 如果您退回任何东西,则跨多个作业共享单个git存储库不是一个好主意。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM