如何为Unreal Engine 5检索Git LFS文件,恢复缺失项目资产
我是Unreal Engine 5(UE5)和Git的新手。昨天我为UE5项目开发了部分功能,完成后保存项目并将变更提交至GitHub仓库。今天继续工作时,发现UE5内容浏览器里部分变更内容不见了;查看项目目录后发现这些文件确实存在,但在VS里打开显示为Git LFS指针文件,UE5没法识别。我想不用重新开始就能让UE5找回这些文件。我试过git lfs checkout、git lfs fetch或git lfs push --all命令,但作为新手不清楚它们的作用,而且没解决问题。
补充:执行GIT_TRACE=1 GIT_TRANSFER_TRACE=1 GIT_CURL_VERBOSE=1 git lfs pull的输出(因篇幅限制跳过部分资产,LFS已列出所有资产包括缺失的那些):
19:10:03.389848 exec-cmd.c:244 trace: resolved executable dir: C:/Program Files/Git/mingw64/bin 19:10:03.396759 git.c:749 trace: exec: git-lfs pull 19:10:03.396759 run-command.c:659 trace: run_command: git-lfs pull 19:10:03.413239 trace git-lfs: exec: git 'version' 19:10:03.467970 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-dir' '--show-toplevel' 19:10:03.515017 trace git-lfs: exec: uname 19:10:03.558384 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository' 19:10:03.588318 trace git-lfs: exec: git 'config' '--includes' '--local' 'lfs.repositoryformatversion' 19:10:03.619662 trace git-lfs: exec: git 'config' '--includes' '-l' 19:10:03.648823 trace git-lfs: exec: git 'rev-parse' '--is-bare-repository' 19:10:03.680204 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' ':.lfsconfig' 19:10:03.710582 trace git-lfs: exec: git 'config' '--includes' '-l' '--blob' 'HEAD:.lfsconfig' 19:10:03.742107 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' 'HEAD' '--symbolic-full-name' 'HEAD' 19:10:03.776202 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' 'HEAD' '--symbolic-full-name' 'HEAD' 19:10:03.804317 trace git-lfs: tq: running as batched queue, batch size of 100 19:10:03.805431 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'ls-tree' '-r' '-l' '-z' '--full-tree' '076b86abd8bf39b957600f4b3165891afc56aeff' 19:10:03.809660 trace git-lfs: exec: git '-c' 'filter.lfs.smudge=' '-c' 'filter.lfs.clean=' '-c' 'filter.lfs.process=' '-c' 'filter.lfs.required=false' 'rev-parse' '--git-common-dir' 19:10:03.874097 trace git-lfs: filepathfilter: accepting ".gitattributes" 19:10:03.874312 trace git-lfs: filepathfilter: accepting ".gitignore" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Config/DefaultEditor.ini" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Config/DefaultEditorPerProjectUserSettings.ini" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Config/DefaultGame.ini" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_CrouchWalk_Aim_F_Loop.uasset" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_CrouchWalk_Aim_F_Loop_IPC.uasset" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_Crouch_Aim_Idle_v2.uasset" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_Crouch_Aim_Idle_v2_IPC.uasset" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_Crouch_Aim_Point_Center.uasset" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_Crouch_Aim_Point_D90.uasset" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_Crouch_Aim_Point_U90.uasset" 19:10:03.874312 trace git-lfs: filepathfilter: accepting "Content/Assets/Animations/Manny/Mobility/W2_Crouch_Fire_Single.uasset" 19:10:13.725078 trace git-lfs: filepathfilter: creating pattern ".git" of type gitignore 19:10:13.725078 trace git-lfs: filepathfilter: creating pattern "**/.git" of type gitignore 19:10:13.725078 trace git-lfs: filepathfilter: accepting "tmp"
从日志来看,Git LFS已经识别到所有缺失的资产,但未将指针文件替换为实际资产文件。按以下步骤操作:
强制清理并重新拉取LFS资产
先清理本地LFS缓存,再强制拉取最新资产:git lfs clean git lfs pull --forcegit lfs clean会清除本地缓存的LFS临时文件,--force参数会强制覆盖本地的指针文件,替换为仓库中的实际资产。检查并修复Git LFS过滤器配置
若LFS的smudge过滤器未正确启用,会导致指针文件无法自动替换为实际内容。执行以下命令配置过滤器:git config filter.lfs.smudge "git-lfs smudge -- %f" git config filter.lfs.clean "git-lfs clean -- %f" git config filter.lfs.process "git-lfs filter-process" git config filter.lfs.required true这些命令确保Git在拉取文件时,自动通过LFS处理大文件资产。
针对单个文件手动替换指针
如果批量拉取无效,找到具体缺失的文件路径(比如日志中提到的Content/Assets/Animations/Manny/Mobility/W2_CrouchWalk_Aim_F_Loop.uasset),执行:git lfs checkout <文件路径>该命令会单独拉取并替换指定的LFS文件。
重启UE5并刷新内容浏览器
完成上述操作后,关闭UE5重新打开项目,在内容浏览器右键空白处选择刷新或按F5键,UE5即可识别实际资产文件。
内容的提问来源于stack exchange,提问作者Olaf Korczak

