如何使用Git LFS进行变基(rebase)?

7

我有一个 repoA,其中包含 2 个受 lfs 跟踪的文件。我将这个 repo 导入到 repoB 中,方法如下:

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

这段代码会打印多行 "Applying: ...",随后执行其他操作。

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".

我该如何解决这个问题?注意:此文件在repoA中不存在。这个问题似乎完全与git lfs有关。

git status显示了以下内容:

$ 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")

注意:我尝试仅添加并提交了这两个文件(voodoo),然后运行 git rebase --continue,直到历史记录中下一次修改该文件的时间点,此时出现了类似的错误。我重复了同样的操作,最终完成了。但是当我尝试将其变基到另一个分支时,出现了问题。
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

这似乎表明我不知道如何正确使用git lfs。

更新1

事实证明,您需要在每个仓库中安装git lfs。这在文档中并不明显地指出。

You only have to set up Git LFS once.

 git lfs install

原来它只是每个代码库一次,而不是真正的"once"。

然后,阅读问题时需要知道从哪里获取远程存储的文件。它基于正在跟踪的任何远程分支来做到这一点,因此重新开始。

git clone git@github.com/me/repoA
cd repoA
git lfs install
git remote add repoB git@github.com/me/repoB
git fetch repoB
git checkout -b temp repoB/somebranch

这将开始检出repoB/somebranch到临时目录,但失败了。
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

据我所知,我现在正在追踪正确的分支。这是与上传文件使用的相同的远程同一分支。

更新2

重新开始上一个操作,但将origin更改为克隆repoA之后指向repoB,则可以进一步操作。

git clone git@github.com/me/repoA
cd repoA
git lfs install
git remote remove origin
git remote add origin git@github.com/me/repoB
git fetch repoB
git checkout -b temp origin/somebranch

这个在之前失败的地方现在可以正常工作了。

但是现在

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

在之前的同一个位置失败

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".

为什么会被踩呢?git-lfs 相对较新,文档也比较稀少。随着它变得越来越流行,其他人遇到这些问题并需要解决方案的可能性不大吗? - gman
2个回答

5
好的,显然问题是当git调用hooks时,它不会传递当前跟踪分支信息,因此lfs无法找到文件。它只会默认使用origin的链接。
所以你需要使用--skip-smudge选项安装lfs。这基本上告诉lfs不要下载文件。像预期的那样进行合并,然后使用git lfs pull, 它有一个远程参数,让你告诉它从哪里获取文件。
一旦完成,我假设你可以键入git lfs install,使其恢复正常。你可能需要执行git lfs fetch --all repoBgit lfs push --all repoA somebranch来将你从先前repo的lfs存储(repoB)下载的所有文件推送到新的repo的lfs存储中(repoA)。
所有步骤请参考此github问题
# This disables smudging for the 'git clone'
# and then calls 'git lfs pull' for you
git lfs clone git@github.com: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

git lfs pull 命令本质上相当于调用 git lfs fetch(下载 LFS 对象)和 git lfs checkout(将本地下载的文件复制到您的工作目录)。因此,我的示例只通过 git lfs fetch --all 命令下载对象。

如果您想要针对单个命令禁用 smudge 过滤器,您也可以使用 GIT_LFS_SKIP_SMUDGE

$ GIT_LFS_SKIP_SMUDGE=1 git pull
$ git lfs pull

这对我来说稍微有些不同的顺序,但关键是要执行以下命令:git lfs install --skip-smudge --local # 执行任何失败的 git 命令,对我来说是检出一个已获取的分支 git lfs checkout # 获取与检出相关联的 LFS 文件 git lfs install --force --local # 重新安装常规的 LFS 使用 - Jock

0

repoA的提交修改了文件Assets/HappyFunTimes/HappyFunTimesCore/Server/Resources/HFTOSXServer.bytes

这个相同的文件也在repoB的工作树中。Git会提示你无法替换该文件。为了纠正它,你必须按照Git建议的方式进行操作。Git经常告诉你如何纠正错误。

存储或提交您的本地更改。在您的情况下,最好是存储您的更改,执行rebase,然后弹出存储。这给出以下命令。

cd repoB
git stash
git fetch repoA somebranch
git checkout -b temp FETCH_HEAD
git rebase someotherbranch
git stash pop // You may need to resolve conflict using git mergetool

开始之前,请确保避免之前的变基尝试。


1
谢谢,但是在repoA中根本不存在该文件。整个路径在repoA中都不存在。这个错误与git lfs有关(或者我认为是这样)。您可以在此处查看repoA,以查看我让它工作之前的状态。您可以看到根目录中没有“Assets”文件夹。 - gman

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接