Locking binary files using git version control system

前端 未结 17 1926
既然无缘
既然无缘 2020-11-28 03:54

For one and a half years, I have been keeping my eyes on the git community in hopes of making the switch away from SVN. One particular issue holding me back is the inabilit

17条回答
  •  清歌不尽
    2020-11-28 04:51

    We've just recently started using Git (used Subversion previously) and I have found a change to workflow that might help with your problem, without the need for locks. It takes advantage of how git is designed and how easy branches are.

    Basically, it boils down to pushing to a non-master branch, doing a review of that branch, and then merging into the master branch (or whichever the target branch is).

    The way git is "intended" to be used, each developer publishes their own public repository, which they request others to pull from. I've found that Subversion users have trouble with that. So, instead, we push to branch trees in the central repository, with each user having their own branch tree. For instance, a hierarchy like this might work:

    users/a/feature1
    users/a/feature2
    users/b/feature3
    teams/d/featurey
    

    Feel free to use your own structure. Note I'm also showing topic branches, another common git idiom.

    Then in a local repo for user a:

    feature1
    feature2
    

    And to get it to central server (origin):

    git push origin feature1:users/a/feature1
    

    (this can probably be simplified with configuration changes)

    Anyway, once feature1 is reviewed, whomever is responsible (in our case, it's the developer of the feature, you could have a single user responsible for merges to master), does the following:

    git checkout master
    git pull
    git merge users/name/feature1
    git push
    

    The pull does a fetch (pulling any new master changes and the feature branch) and the updates master to what the central repository has. If user a did their job and tracked master properly, there should be no problems with the merge.

    All this means that, even if a user or remote team makes a change to a binary resource, it gets reviewed before it gets incorporated into the master branch. And there is a clear delineation (based on process) as to when something goes into the master branch.

    You can also programmatically enforce aspects of this using git hooks, but again, I've not worked with these yet, so can't speak on them.

提交回复
热议问题