跳至主要内容

What is git-lfs and how to convert existing repo

What is git-lfs

According to its name, git-lfs is git-large-file-storage. Is a git plugin which replace large file to their corresponding text pointers in git repo.

This way it accelerates git fetch process by only download needed large file objects.

Why git-lfs?

Git service provider such as GitHub and bitbucket are both activated the git-lfs on their service.

Actually, github also setup a hook that will reject commits with large binary files.

If you have a legacy git repository and want to host it on GitHub, you must make sure there's no large binary files ever checked into your repo in the past.

What if you got a poisoned repo full of large binary files?

There are no many options to choose from when you are in this situation.

  1. Convert or migrate to git-lfs repo.
  2. Drop the history, as huge git-lfs do cost money. Both github and bitbucket set 1GB limit on their free git-lfs storage capacity.

Enable git-lfs in new repo and Convert existing repo to git-lfs repo with git

There's an offical solution to this task, on git-lfs homepage. The procedure to enable git-lfs is very simple, in nutshell contains following steps:

cd <REPO>
git lfs install
git lfs track "*.psd"

migration is alo provided in its dedicated page, as shown bellow:

git lfs migrate info
git lfs migrate import --include="*.mp3,*.psd"

Convert existing repo to git-lfs repo with bfg

The full name of the utility is bfg-repo-cleaner. As the name stated it can do all kinds of git repo cleanup tasks. One of its feature is to convert the git history to git-lfs.

The tool runs very fast, and will present a nice looking ASCII report for the operation.

The procedure consists of only one command as:

java -jar <path to>bfg-x.x.x.jar --convert-to-git-lfs "*.{png,mp4}" --no-blob-protection <repo-name>.git

评论

此博客中的热门博文

XEmacs 21.5 beta 35 "kohlrabi" has been released.

If you are an old XEmacs user, you may feel happy to see this from https://www.xemacs.org/.    After ten years, XEmacs released a new version 21.5. So there's still many people cares about XEmacs. The XEmacs' source repo have been moved from altassian Bitbucket to https://heptapod.net/. As Bitbucket have been dropped Mercurial support many years ago.

Fido-mode

Today, I've just discovered the Fido mode, a modified `icomplete` minor mode. `icomplete` used to be one of my favorite mode days back to my XEmacs days. Pros: It is way fast. It is much more smart in terms of find the complete candidate that you want mostly.  Cons: It does not integrate well enough with tramp yet.    `fido-mode` is a core package of Emacs 27+, and there's a vertical version available after Emacs 28+ named `fido-vertical-mode`. UPDATE: I am back with ido now