Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to rebase with git lfs?

Tags:

git

git-lfs

I've got a repoA with 2 lfs tracked files. I'm bringing that repo into repoB like this

cd repoB
git fetch repoA somebranch
git checkout -b temp FETCH_HEAD
git rebase someotherbranch

this prints several lines of "Applying: ..." and then

Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
error: Your local changes to the following files would be overwritten by merge:
    Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes
Please, commit your changes or stash them before you can merge.
Aborting
error: Failed to merge in the changes.
Patch failed at 0340 update server
The copy of the patch that failed is found in: .git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".

How do I fix this? NOTE: THIS FILE DOES NOT EXIST IN repoA. This issue seems to be entirely related to issues with git lfs.

git status showed this

$ git status
rebase in progress; onto 5af1f30
You are currently rebasing branch 'gamepad' on '5af1f30'.
  (all conflicts fixed: run "git rebase --continue")

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git checkout -- <file>..." to discard changes in working directory)

    modified:   Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes
    deleted:    Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.sha256.bytes

no changes added to commit (use "git add" and/or "git commit -a")

Note: I tried just adding and committing the 2 files (voodoo) and then git rebase --continue which kept going until the next time the file was modified in the history at which point it got a similar error. I did the same thing and it finally finished. But then when I tried to rebase that onto another branch I got

Downloading Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes (7.48 MB)
Error downloading object: Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes (4743b094eeab821140773213ebabdaa81c9ac2eb1be1108e70e8d51ae52873dd)

Errors logged to /Users/gregg/src/hft-unity3d/.git/lfs/objects/logs/20160603T213456.110362284.log
Use `git lfs logs last` to view the log.
error: external filter git-lfs smudge -- %f failed 2
error: external filter git-lfs smudge -- %f failed
fatal: Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes: smudge filter lfs failed
Could not apply dc378b5d715103e9af0ee805ff2a3be1159739aa... add lfs support

Which kind of suggests I have no clue how to use git lfs correctly.

update 1

So it turns out you have to install git lfs in every repo. This is not at all clear from the docs which say

You only have to set up Git LFS once.

 git lfs install

It turns out it's once per repo not actually once.

Then, reading though the issues it needs to know where to get the remotely stored files. It does this based on whatever remote branch is being tracked so, starting over

git clone [email protected]/me/repoA
cd repoA
git lfs install
git remote add repoB [email protected]/me/repoB
git fetch repoB
git checkout -b temp repoB/somebranch

This starts to checkout repoB/somebranch into a temp but fails with

Downloading Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes (7.48 MB)
Error downloading object: Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes (f8c42a7c55f610768ce50ff93d09fc63fa897de867290dafee2e84d64e10de4e)

Errors logged to /Users/gregg/temp/delme-hft-unity3d/.git/lfs/objects/logs/20160603T231351.670335751.log
Use `git lfs logs last` to view the log.
error: external filter git-lfs smudge -- %f failed 2
error: external filter git-lfs smudge -- %f failed
fatal: Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes: smudge filter lfs failed

AFAIK I'm tracking the correct branch now. That's the same branch on the same remote that the files were uploaded with.

update 2

Starting over with the last one but changing origin to point to the repoB after cloning repoA gets further

git clone [email protected]/me/repoA
cd repoA
git lfs install
git remote remove origin
git remote add origin [email protected]/me/repoB
git fetch repoB
git checkout -b temp origin/somebranch

This works where as before it failed

But now

git checkout -b other master
git branch --set-upstream-to origin/somebranch
git rebase master temp

Fails at the same place as before

Using index info to reconstruct a base tree...
Falling back to patching base and 3-way merge...
error: Your local changes to the following files would be overwritten by merge:
    Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes
Please, commit your changes or stash them before you can merge.
Aborting
error: Failed to merge in the changes.
Patch failed at 0358 update server
The copy of the patch that failed is found in: .git/rebase-apply/patch

When you have resolved this problem, run "git rebase --continue".
If you prefer to skip this patch, run "git rebase --skip" instead.
To check out the original branch and stop rebasing, run "git rebase --abort".
like image 277
gman Avatar asked Jun 03 '16 13:06

gman


1 Answers

Okay apparently the issue is when git calls hooks it doesn't pass the current tracking branch info so lfs has no way to find the files. It just defaults to using origin's link

So to do this you need to install lfs with the --skip-smudge option. this will basically tell lfs not to download the files. Do the merges as expected, then git lfs pull which has a remote parameter to let you tell it where to get the files

Once it's all done I'm assuming you can type git lfs install to get it somewhat back to normal. You probably need to do a git lfs fetch --all repoB and git lfs push --all repoA somebranch to get all your the files you downloaded from the previous repo's lfs store (repoB) to the new repo's lfs store (repoA)

all the steps from this github issue

# This disables smudging for the 'git clone'
# and then calls 'git lfs pull' for you
git lfs clone [email protected]:me/repoB.git
cd repoB
git lfs install --skip-smudge --local # affects only this clone

git fetch repoA
git checkout -b temp repoA/somebranch
git rebase master

git lfs fetch --all repoA
git lfs checkout
git push origin temp

git lfs push --all origin temp
git lfs install --force --local

The git lfs pull command is essentially the same as calling git lfs fetch (downloads LFS objects) and git lfs checkout (copies the locally downloaded files to your working directory). So, my example only downloads objects through the git lfs fetch --all command.

If you want to disable the smudge filter for a single command, you can also use GIT_LFS_SKIP_SMUDGE:

$ GIT_LFS_SKIP_SMUDGE=1 git pull
$ git lfs pull
like image 174
gman Avatar answered Sep 18 '22 17:09

gman