将功能分支合并到master以启用git LFSgit后如何建议开发人员

问题描述

详细信息

  • 我们正在尝试将我们的仓库迁移到git LFS
  • 我有一个将启用git lfs的分支,我正在做的是更新.gitattributes文件,并创建一个跟踪器,该跟踪器又创建了指针来跟踪需要成为LFS一部分的所有文件
  • 现在,一旦将此功能分支合并到认/主版本中,我将不得不告知开发人员他们需要做什么。

我需要了解的问题?

  • 现在,我所建议和发现的通常是在更新到master / default之前,即重新设置为master / default之前,我告诉他们对它们拥有的所有功能分支执行以下操作,直到现在为止没有git lfs更改
brew install git-lfs (this will be system-wide)
git lfs install (this will be on the root directory of the repo,for each branch)
  • 现在对于开发人员来说,这将是一个手动步骤,他们以某种方式希望对他们而言是自动化的,我认为这可以通过git hooks或其他方式完成,从而他们不必更新每个分支 我正在考虑执行bash命令,这样可以吗?这可行
for branch in $(git for-each-ref --format='%(refname)' refs/heads/); do 
    git lfs install "$branch"; 
done

更新1

  • 似乎上述内容确实会对您在本地历史记录中的所有分支机构执行git lfs install,并且一次完成。
  • 但是我仍然想知道和理解什么是best练习

解决方法

在所有分支机构中都不需要运行git lfs install -在仓库中执行install后,它将为该仓库永久设置。从帮助中:

$ git lfs install --help
git lfs install [options]

Perform the following actions to ensure that Git LFS is setup properly:

* Set up the clean and smudge filters under the name "lfs" in the global Git
  config.
* Install a pre-push hook to run git lfs pre-push for the current repository,if run from inside one. If "core.hooksPath" is configured in any Git
  configuration (and supported,i.e.,the installed Git version is at least
  2.9.0),then the pre-push hook will be installed to that directory instead.

挂钩存储在.git文件夹中,因此当您签出其他分支时它们不会受到影响。

现在,您似乎已经知道,如果人们的分支早于新.gitattributes文件的合并,那么他们将需要重新设置这些分支的基础以获取更改并确保正确的文件视为LFS的。但这与git lfs install无关。