如何在我的分支比主人提前5次提交时在提交中删除过大的文件 [英] How to remove a too large file in a commit when my branch is ahead of master by 5 commits

查看:565
本文介绍了如何在我的分支比主人提前5次提交时在提交中删除过大的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在这个问题上停留一整天,在这里寻找答案:( ...



上下文



我一个人在一个项目上工作,直到现在我用github来保存我的工作,而不是在我的电脑上。
不幸的是,我添加了一个非常大的文件本地存储库:300MB(超过Github的限制)。



我做了什么

我会尝试记录我所做的事情:


  1. 我(笨拙地)将所有内容添加到索引中:

      git add * 


  2. 我提交了更改:

      git commit -mBlablabla


    $ p $ <$ p $ <$ p $ <$> code> git push origin master

    花了一段时间,所以我只是CTRL + C,并重复第2步和第3步四次,直到我意识到文件太大而无法推送到github。


  3. 我犯了一个可怕的错误来删除我的大文件(我不记得我是做了一个git rm还是一个简单的rm)

  4. 我遵循( https://help.github.com/articles/remove-sensitive-data 当我尝试git过滤分支时,出现以下错误:无法重写分支:您有未分离的更改。

    >

预先感谢!

当你删除你的文件时,这将是一个变化,这是git抱怨的未分阶段变化。如果你做一个git状态,你应该看到列出的文件被删除/删除。要撤销这个更改,您应该 git checkout - < filename> 。然后文件将回来,你的分支应该是干净的。你也可以 git reset --hard 这会使你的repo回到你提交的状态。



我假设它是最后一次提交,它包含您要删除的非常大的文件。您可以执行 git reset HEAD〜然后您可以重做提交(不添加大文件)。那么你应该可以毫无问题地 git push

由于该文件不在上次提交中,因此您可以在没有问题的情况下执行最后一个步骤。您只需要提交或删除您的更改。



http://git-scm.com/book/en/Git-Tools-Rewriting-History


I've been stuck all day on this issue, looking for an answer here :( ...

Context

I'm working alone on a project and I used github until now to save my work other than on my computer. Unfortunately, I added a very large file to the local repository : 300mb (which exceed Github's limit).

What I did

I will try to make an history of what I made :

  1. I (dumbly) added everything to the index :

    git add *
    

  2. I committed changes :

    git commit -m "Blablabla"
    

  3. I tried to push to origin master

    git push origin master 
    

    It took a while, so I just CTRL+C, and repeated step 2 and 3 four times, until I realised that a file was too large to be pushed to github.

  4. I made the terrible mistake to delete my large file (I don't remember if I did a git rm or a simple rm)

  5. I followed the instructions on (https://help.github.com/articles/remove-sensitive-data)

  6. When I try to git filter branch, I get the following error : "Cannot rewrite branches: You have unstaged changes."

Thanks in advance !

解决方案

When you deleted your file, that will be a change and that is the unstaged change that git is complaining about. If you do a git status you should see the file listed as removed/deleted. To undo this change you should git checkout -- <filename>. Then the file will be back and your branch should be clean. You can also git reset --hard this will bring your repo back to the status where you made your commit.

I am assuming that it is the last commit that has the very large file that you want to remove. You can do a git reset HEAD~ Then you can redo the commit (not adding the large file). Then you should be able to git push without a problem.

Since the file is not in the last commit then you can do the final steps without a problem. You just need to get your changes either committed or removed.

http://git-scm.com/book/en/Git-Tools-Rewriting-History

这篇关于如何在我的分支比主人提前5次提交时在提交中删除过大的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆