从git respository中排除大文件
我想告诉git不要将大于250 MB的文件提交到我的远程存储库 首先,启动存储库:从git respository中排除大文件,git,powershell,gitignore,Git,Powershell,Gitignore,我想告诉git不要将大于250 MB的文件提交到我的远程存储库 首先,启动存储库: cd existing_folder git init git remote add origin https://git.xxx.com/username/repository_name.git 接下来,我想告诉git,不要将大于200 MB的文件提交到我的远程存储库。为此,我在Stackoverflow上找到了答案,建议运行以下代码 echo "# Files over 250mb" &
cd existing_folder
git init
git remote add origin https://git.xxx.com/username/repository_name.git
接下来,我想告诉git,不要将大于200 MB的文件提交到我的远程存储库。为此,我在Stackoverflow上找到了答案,建议运行以下代码
echo "# Files over 250mb" >> .gitignore
find * -size +250M -type f -print >> .gitignore
但是,当我在Windows PowerShell中运行代码时,它会说
PS C:\Users\Username\Rep> find * -size +250M -type f -print >> .gitignore
find : FIND: Parameter format not correct
At line:1 char:1
+ find * -size +250M -type f -print >> .gitignore
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : NotSpecified: (FIND: Parameter format not correct:String) [], RemoteException
+ FullyQualifiedErrorId : NativeCommandError
接下来,我将运行以下代码。据我所知,从理论上讲,从现在起git将始终排除大于250MB的文件
git add .
git commit -m "Initial commit"
git push -u origin main
我如何才能正确地告诉git不要将大于250MB的文件提交到我的远程存储库?您的答案的问题是,您只忽略在添加到
时发现的那些文件。gitignore
。如果要在每次提交时进行检查,您有2个选项:
预提交
钩子检查索引中每个文件的大小是否小于250MB。我在Linux上,所以我无法为您编写脚本(实际上我不确定它是否在Git bash for Windows上工作),但您主要需要2个命令:
:获取索引中每个文件的名称和blobgit ls files-s
:获取从上一个命令检索到的git cat file-s
的大小
此注释将创建一个
.gitignore
文件,其中包含注释#超过250 MB的文件
:写入输出“#超过250 MB的文件”|输出文件-文件路径。\.gitignore
。此命令将添加超过一定大小的所有文件,但文件路径在引号之间给出,而不是作为相对文件路径:forfiles/P“C:\Users\UserName\Folder”/M*/S/C“CMD/C if@fsize gtr 250000000 echo@path”| Out file-FilePath-Append.\.gitignore
。