我在几次提交前不小心提交了一个大文件,后来我删除了它并提交了它,但是当我尝试推送时出现错误:
'remote: error: GH001: Large files detected.'
Run Code Online (Sandbox Code Playgroud)
有什么方法可以只推送存储库的当前状态并忽略我删除的那些文件?
更新
当我运行 git rebase 时我得到这个..
C:\Data\unity\GameX4 [patching]> git rebase 4a877be9acb7dbabb46b9aec367d68b2fec7c884
First, rewinding head to replay your work on top of it...
Applying: smaller particles again
Applying: sdgs
Using index info to reconstruct a base tree...
M Assets/01_GRAPHICS/03_UNITY_MATERIALS/metaballmat.mat
Falling back to patching base and 3-way merge...
warning: Cannot merge binary files: Assets/01_GRAPHICS/03_UNITY_MATERIALS/metaballmat.mat (HEAD vs. sdgs)
Auto-merging Assets/01_GRAPHICS/03_UNITY_MATERIALS/metaballmat.mat
CONFLICT (content): Merge conflict in Assets/01_GRAPHICS/03_UNITY_MATERIALS/metaballmat.mat
Failed to merge in the changes.
Patch failed at 0002 sdgs
The copy of the patch that failed is found in:
c:/Data/unity/GameX4/.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".
C:\Data\unity\GameX4 [(1697860...)|REBASE +0 ~3 -0 !1 | +0 ~0 -0 !1]>
Run Code Online (Sandbox Code Playgroud)
在您的情况下,使用git filter-branch从所有以前的提交中删除有问题的文件
使用命令删除file_name_to_remove
git filter-branch --force --index-filter \
'git rm -r --cached --ignore-unmatch file_name_to_remove' \
--prune-empty --tag-name-filter cat -- --all
Run Code Online (Sandbox Code Playgroud)过滤器分支完成后,验证是否没有丢失意外的文件。
现在添加 .gitignore 规则
echo "file_name_to_remove" >> .gitignore
git add .gitignore && commit -m "removing filename"
Run Code Online (Sandbox Code Playgroud)现在做一个推
git push -f origin branch
Run Code Online (Sandbox Code Playgroud)如果您已经推送了分支,因为提交已被重写,您将需要执行强制推送。否则,如果更改仅是本地的,您也可以进行正常的推送。额外的优点是,如果您在多次提交中添加了此文件,则可以将其从所有提交的历史记录中完全删除。
| 归档时间: |
|
| 查看次数: |
1289 次 |
| 最近记录: |