6

我有一个带有 2 个 lfs 跟踪文件的 repoA。我正在像这样将那个 repo 带入 repoB

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

这会打印几行“正在应用:...”,然后

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

注意:我尝试只添加并提交 2 个文件(巫毒教),然后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

所以事实证明你必须在每个 repo 中安装 git lfs。这一点从文档中说不清楚

您只需设置一次 Git LFS。

 git lfs install

事实证明它是每个 repo 一次,而不是一次

然后,阅读它需要知道从哪里获取远程存储文件的问题。它根据正在跟踪的任何远程分支执行此操作,因此重新开始

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

AFAIK 我现在正在跟踪正确的分支。这是上传文件的同一个遥控器上的同一个分支。

更新 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".
4

2 回答 2

5

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

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
于 2016-06-03T15:56:34.323 回答
0

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

同样的文件也在repoB工作树中。Git 知道它不能替换文件。要纠正它,您必须按照 git 的建议进行操作。Git 经常告诉你如何纠正错误。

存储或提交您的本地更改。在您的情况下,最好隐藏您的更改,执行变基,弹出存储。这会给你以下命令。

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

在开始之前,一定要避免以前的 rebase 尝试。

于 2016-06-03T13:39:02.147 回答