首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Git LFS不推送LFS文件,除非我用对象id指定它们。

Git LFS不推送LFS文件,除非我用对象id指定它们。
EN

Stack Overflow用户
提问于 2020-01-22 11:30:51
回答 1查看 2.9K关注 0票数 0

我在Azure DevOps上托管了一个使用LFS的回购程序。当推送提交时,新的LFS对象不会与它一起推送(如果我在一个单独的存储库中提取更改,它会生成Smudge Error: Object does not exist on server [404])。

要推送LFS对象的唯一方法是通过指定对象id来手动完成它:

git lfs push origin --object-id ae488...

这是我的git config -l

代码语言:javascript
复制
$ git config -l
http.sslcainfo=C:/Users/200207121/AppData/Local/Programs/Git/mingw64/ssl/certs/ca-bundle.crt
http.sslbackend=openssl
diff.astextplain.textconv=astextplain
core.autocrlf=true
core.fscache=true
core.symlinks=false
core.editor="C:\\Program Files\\Notepad++\\notepad++.exe" -multiInst -notabbar -nosession -noPlugin
credential.helper=manager
filter.lfs.clean=git-lfs clean -- %f
filter.lfs.smudge=git-lfs smudge -- %f
filter.lfs.process=git-lfs filter-process
filter.lfs.required=true
user.email=<omitted>
user.name=<omitted>
alias.lg=log --color --graph --pretty=format:'%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset' --abbrev-commit
http.sslverify=false
diff.tool=default-difftool
difftool.default-difftool.cmd=code --wait --diff $LOCAL $REMOTE
merge.tool=vscode
mergetool.vscode.cmd=code --wait $MERGED
core.repositoryformatversion=0
core.filemode=false
core.bare=false
core.logallrefupdates=true
core.symlinks=false
core.ignorecase=true
remote.origin.url=https://.../MyRepo/_git/MyRepo
remote.origin.fetch=+refs/heads/*:refs/remotes/origin/*
branch.master.remote=origin
branch.master.merge=refs/heads/master
lfs.https://dev.azure.com/.../MyRepo.git/info/lfs.access=basic
lfs.https://dev.azure.com/.../MyRepo/info/lfs/objects/.access=basic
branch.7_1_0.remote=origin
branch.7_1_0.merge=refs/heads/7_1_0
branch.7_1_A.remote=origin
branch.7_1_A.merge=refs/heads/7_1_A
branch.atvcm01008318_text_class.remote=origin
branch.atvcm01008318_text_class.merge=refs/heads/text_class
branch.atvcm01008824.remote=origin
branch.atvcm01008824.merge=refs/heads/atvcm01008824
branch.atvcm01000423.remote=origin
branch.atvcm01000423.merge=refs/heads/atvcm01000423
gui.wmstate=normal
gui.geometry=1272x626+-5+0 254 315

为了防止特定分支被推开,我在pre-push钩子中添加了这些行。我目前没有在这个分支上签出,我试图推动的LFS也不在这个分支上(所以我不怀疑它可能是由这个钩子引起的):

代码语言:javascript
复制
#!/bin/sh

### Prevent pushing test branch
if [[ `grep 'testing_AA'` ]]; then 
  echo "You really don't want to push this branch. Aborting."
  exit 1
fi
### End of edition

command -v git-lfs >/dev/null 2>&1 || { echo >&2 "\nThis repository is configured for Git LFS but 'git-lfs' was not found on your path. If you no longer wish to use Git LFS, remove this hook by deleting .git/hooks/pre-push.\n"; exit 2; }
git lfs pre-push "$@"

为什么我必须指定git lfs push --object-id <oid>来推动LFS?

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2020-01-24 03:07:00

pre-push钩子的工作方式是从标准输入中读取行,这些行指示要推送哪些引用以及它们的新旧值是什么。与您的脚本一样,git lfs pre-push作为预推送钩子工作,并在其标准输入中期望这些数据。然后,它确定需要在此基础上推送哪些LFS对象,并推送它们。

pre-push钩子所做的是用grep读取所有标准输入。然后在没有输入的情况下调用git lfs pre-push。因为Git认为没有参考文献可以推送(因为它的标准输入中没有提供引用),所以它没有推送任何内容。

如果您想在推送特定引用的情况下中止操作,则需要让预推钩子一次解析标准输入一行,如果与行匹配则中止,如果不匹配,则将其附加到git lfs pre-push的未来输入中。如下所示:

代码语言:javascript
复制
#!/bin/sh

INPUT=""

while read line
do
    if echo $line | grep -qs 'testing_AA'
    then
        echo "You really don't want to push this branch. Aborting." >&2
        exit 1
    fi
    INPUT="$INPUT $line"
done

printf "%s %s %s %s\n" $INPUT | git lfs pre-push "$@"
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/59858769

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档