Locking binary files using git version control system

前端 未结 17 1857
既然无缘
既然无缘 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:44

    This is not a solution but rather a comment on why locking mechanisms are needed. There are some tools used in some fields which use binary only formats which are flat out mission critical and the "use better/different tools" is just not an option. There are no viable alternate tools. The ones I'm familiar with really wouldn't be candidates for merging even if you stored the same information in an ascii format. One objection I've heard is that you want to be able to work offline. The particular tool I'm thinking of really doesn't work offline anyway because of needing to pull licenses so if I have data on a laptop it isn't like I can run the tool while on a train anyway. That said, what git does provide if I have a slow connection, I can get licenses and also pull down changes but have the fast local copy for looking at different versions. That is a nice thing that the DVCS gives you even in this case.

    One view point is that git is simply not the tool to use but it is nice for all the text files which are also managed with it and it is annoying to need different version control tools for different files.

    The sort-of-advisory-locking-via-mail approach really stinks. I've seen that and have been tired of an endless stream of emails of "I'm editing it" "I'm done editing" and seen changes lost because of it. The particular case I'm thinking of was one where a collection of smaller ascii files would have been much nicer but that is an aside.

    0 讨论(0)
  • 2020-11-28 04:46

    Subversion has locks, and they aren't just advisory. They can be enforced using the svn:needs-lock attribute (but can also be deliberately broken if necessary). It's the right solution for managing non-mergeable files. The company I work for stores just about everything in Subversion, and uses svn:needs-lock for all non-mergeable files.

    I disagree with "locks are just a communication method". They are a much more effective method than push-notifications such as phone or e-mail. Subversion locks are self-documenting (who has the lock). On the other hand, if you have to communicate by other traditional push-notification channels, such as e-mail, who do you send the notification to? You don't know in advance who might want to edit the file, especially on open-source projects, unless you have a complete list of your entire development team. So those traditional communication methods aren't nearly as effective.

    A central lock server, while against the principles of DVCS, is the only feasible method for non-mergeable files. As long as DVCS don't have a central lock feature, I think it will keep the company I work for using Subversion.

    The better solution would be to make a merge tool for all your binary file formats, but that's a longer-term and ongoing goal that will never be "finished".

    Here's an interesting read on the topic.

    0 讨论(0)
  • 2020-11-28 04:46

    It's worth examining your current workflow to see if locking images is really necessary. It's relatively unusual for two people to independently edit an image, and a bit of communication can go a long way.

    0 讨论(0)
  • 2020-11-28 04:49

    I agree that locking binary files is a necessary feature for some environments. I just had a thought about how to implement this, though:

    • Have a way of marking a file as "needs-lock" (like the "svn:needs-lock" property).
    • On checkout, git would mark such a file as read-only.
    • A new command git-lock would contact a central lock server running somewhere to ask permission to lock.
    • If the lock server grants permission, mark the file read-write.
    • git-add would inform the lock server of the content hash of the locked file.
    • The lock server would watch for that content hash to appear in a commit on the master repository.
    • When the hash appears, release the lock.

    This is very much a half-baked idea and there are potential holes everywhere. It also goes against the spirit of git, yet it can certainly be useful in some contexts.

    Within a particular organisation, this sort of thing could perhaps be built using a suitable combination of script wrappers and commit hooks.

    0 讨论(0)
  • 2020-11-28 04:50

    TortoiseGit supports full git workflow for Office documents delegating diff to Office itself. It works also delegating to OpenOffice for OpenDocument formats.

    0 讨论(0)
  • 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.

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