跳至主要内容

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

评论

此博客中的热门博文

Eglot and before/after-save-hook and use-package

In Emacs, when you try to automate some actions during every save action, you will surely get to the before-save-hook and the after-save-hook. Simply adding something like gofmt-before-save to before-save-hook will save you tons of time to do the go-fmt. And then, I meet eglot, and gopls will also save me tons of time doing googling and api documentation navigation. But eglot-ensure is not very friendly to the good old ways of how after-save-hooks were designed to work. It makes the before/after-save-hook a buffer local variable and it does not inherit the variable's global value. So, to make before/after-save-hook work again, experts start to adding hooks to major mode specific hooks like this: emacs.md - Go (opensource.google) """ ;; Optional: install eglot-format-buffer as a save hook. ;; The depth of -10 places this before eglot's willSave notification, ;; so that that notification reports the actual contents that will be saved. (defu...

Use MobaDiff with git difftool

Recently there's an activity in IT that forces the deletion of all unauthorized softwares from all work machines. Unfortunately, kdiff3 is one in the list. As it is generally okay to use vimdiff as an alternative for kdiff3, A gui tool is better suited for desktop workflows. Known that MobaXterm is shipping a gui diff tool named MobaDiff. But it only appears in the windows right click context menu. Find the real application name takes me some time to search in the windows registry. "MobaRTE.exe", which is the one invoked by HKCR\*\shell\MobaDiff. And it was invoked with "-contextdiff" switch to show MobaDiff UI, while when the switch is "-contextedit" it shows MobaTextEditor. Too bad that the "-contextdiff" switch do not support pre-image post-image as other diff tool did, which effectively made it unable to be used as a command line diff utility. Also MobaTech did not mention anything in their document of this Mob...