3

Trying to migrate a repo (including history) OUT of Git LFS.

I ran git lfs migrate export --include="*" --everything (mentioned here) on a test repo, but it didn't work as expected and left LFS pointer files instead of converting them all to objects.

I tried alternative methods, following this. Unfortunately it still left pointer files, so I combined it with this.

In the end, I even ran all the commands together:

git lfs uninstall
git filter-branch -f --prune-empty --tree-filter '
  git lfs fetch
  git lfs checkout
  git lfs ls-files | cut -d " " -f 3 | xargs touch
  git lfs ls-files | cut -d " " -f 3 | xargs git rm --cached
  git rm -f .gitattributes
  git lfs ls-files | cut -d " " -f 3 | xargs git add --force
  git add --renormalize .
' --tag-name-filter cat -- --all

Didn't work. Gave me the following error for multiple files, and the filtered commits have pointer files instead of the objects.

Errors logged to <PATH>
Use `git lfs logs last` to view the log.
Rewrite <COMMIT SHA ####> (2/9) (2 seconds passed, remaining 7 predicted)    
Checking out LFS objects:   0% (0/1), 0 B | 0 B/s           
Checking out LFS objects: 100% (2/2), 3.1 KB | 0 B/s, done
Error updating the git index:
error: picture.png: cannot add to the index - missing --add option?
fatal: Unable to process path picture.png

I tried running the same commands on only the tip commit, and it seems like touch, rm --cached, add --renormalize ., add --force don't show any modifications with git status. So I'm unable to re-add the cleaned/pulled object files to a new commit.

Maybe that's the problem? So how to forcibly re-add unchanged file to index when using filter-branch?

(Using Windows with git bash.)

jndi75
  • 43
  • 1
  • 5
  • Did you tried `git lfs migrate export`? See https://stackoverflow.com/a/57681990/717372 – Philippe Jan 01 '20 at 12:28
  • @Philippe That was the first thing I tried. Didn't work somehow... left pointer files in my history, and wiped the LFS objects folder too :( – jndi75 Jan 01 '20 at 23:29
  • @Philippe I reread the post and noticed I set my --include option differently. After following the steps exactly, the content files successfully replaced the pointers. But it gives me a new problem! Checkout of any commit shows the error "Encountered # file(s) that should have been pointers, but weren't", and files appear as modified so git forces me to add them to a new commit. – jndi75 Jan 02 '20 at 00:27
  • I imagine that you got this message because you still have got lfs installed (you have to remove the filters in the `.gitattributes` file) – Philippe Jan 02 '20 at 06:08
  • @Philippe You're right. Afterwards, I did a dummy commit followed by a tree-filter with ```git rm -f .gitattributes```. Worked out nicely. (This surprises me because ```git lfs migrate export``` already added a line to ```.gitattributes``` to negate the lfs filters, but maybe I specified the files incorrectly.) Thanks! If you want to add your answer, I'll accept it (or I can add it). :) – jndi75 Jan 03 '20 at 04:21
  • 1
    I wrote a slightly better answer ;) – Philippe Jan 03 '20 at 09:14

1 Answers1

7
  1. Do a git lfs migrate export --everything --include . to replace all the LFS pointers by the real files in the git history. For more details, see http://stackoverflow.com/a/57681990/717372

  2. Run git lfs uninstall to remove lfs hooks.

  3. And verify that the .gitattributes has the lfs filters removed.

    If the lfs filters were not removed, and if .gitattributes was only needed for LFS, delete the file in all of history with:

    git filter-branch -f --prune-empty --tree-filter '
      git rm -f .gitattributes --ignore-unmatch
    ' --tag-name-filter cat -- --all
    

    Otherwise if .gitattributes has non-LFS lines, remove only the LFS filters by replacing the above tree-filter command with git lfs untrack (reference here and here).

jndi75
  • 43
  • 1
  • 5
Philippe
  • 28,207
  • 6
  • 54
  • 78