我设置了.gitattributes
来制作一些二进制文件LFS。没意识到我已经有了一些git钩子,所以我没有git lfs钩子。我进行了一次推送,现在在上游仓库中,所有二进制文件只是空指针,实际上没有文件上传。
所以我现在安装了正确的git lfs挂钩,但是现在我该怎么做才能实际上传文件? git lfs push
表示一切都是最新的,尽管不是最新的。
我尝试了git rm --cached file.bin && git add file.bin
,但是却什么也没做(状态仍然是最新的)。
答案 0 :(得分:0)
我知道了。只需执行git lfs push <remote> <branch> --all
即可推送文件。
答案 1 :(得分:0)
我想补充一点。 我经常发现,对于非常大的提交(例如,让我们拥有20GB的文件) 如果网络连接完全中断,则git lfs将部分通过推送失败。推送20GB的文件需要很长时间,因此很容易发生。
我编写了这些脚本(mac和Windows)来分别推送每个文件,因此每次上传都是原子的。如果确实失败,则至少可以从您所在的位置重新启动,并且通过原子推送,在单个推送上失败的可能性较小。
Windows(在Git bash上运行)
#!/bin/sh
# This script is for adding files to Git LFS and then pushing them to a repo.
# It assumes you have already initalized git lfs.
#
# Why do you need this script?
# If you need to push a loooooooot of dependencies to Git LFS.
# If you try to push all your files at once in a single commit, any sort of
# interruption in network connectivity could cause the push to fail and then
# you will have to start all over again. This happened to me several times as I # tried to push 24 GB of files via git lfs to a repository. I wrote this script
# to commit and then push each file individually so I could get past that hurdle
# and move on to other things.
# Cons: this makes the commit history rather long, but after you do it once,
# it should be smooth sailing from there. I've never had this con cause me any
# trouble.
# global var definitions
dir=/c/Projects/path/to/local/deps
branch="my-branch"
# function definitions
function add_file_and_push_to_github() {
branch="my-branch"
echo "in here: $1"
git add "$1"
echo "after add"
git commit -m "add $1"
echo "after commit"
git pull origin "${branch}"
echo "after pull ${branch}"
git push origin "${branch}"
echo "after push to ${branch}"
}
rm -rf .git
rm README.md
git init
git remote add origin https://github.com/sitting-duck/MyDependenciesRepo.git
git pull origin master
git checkout -b "$branch"
git lfs install
git add .gitattributes
echo "before push -u $branch"
git push -u origin "$branch"
echo "after push -u $branch"
git lfs track *.lib
git lfs track *.dll
git pull origin "$branch"
export -f add_file_and_push_to_github
find . -type f -print0 | xargs -0 bash -c 'add_file_and_push_to_github "$@"'
MacOS(在终端应用程序中运行)
#!/bin/sh
# global var definitions
dir=/Projects/path/to/dependencies/
branch="my-branch"
rm -rf .git
rm README.md
git init
git remote add origin https://github.com/sitting-duck/myRepo.git
git pull origin master
git checkout -b "$branch"
git lfs install
git add .gitattributes
echo "before push -u $branch"
git push -u origin "$branch"
echo "after push -u $branch"
git lfs track *.dylib
git pull origin "$branch"
while IFS="" read -r p || [ -n "$p" ]
do
printf '%s\n' "$p"
if [[ p != *".git"* ]]; then
branch="my-branch"
echo "in here: $p"
git add "$p"
echo "after add"
git commit -m "add $p"
echo "after commit"
git pull origin "${branch}"
echo "after pull ${branch}"
git push origin "${branch}"
echo "after push to ${branch}"
fi
done < files.txt