从git中删除一个文件,它尚未推送,但也没有在最新的提交? [英] Remove a file from git which is not pushed yet but also not in latest commit?

查看:172
本文介绍了从git中删除一个文件,它尚未推送,但也没有在最新的提交?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现了这个非常棒的git帮助页面:

https://help.github.com/articles/working-with-large-files/



<这两种方法都不适用于我......我认为,因为我试图摆脱的大文件不在最新的提交中,我无法推送......但在最新的状态,我已经删除了文件..这个删除也没有推迟..

所以这就是它的样子:




$在选定的修订版中,b $ b

  • 意外地添加了大笨笨的.mov文件

  • 两次提交后,我将其删除



并且您可以看到我已经尝试过一件事:


  • 在我添加文件git checkout blabla后,我切换回了修订版

  • 我删除了文件git rm /assets/video/landed.mov。

  • 我做了一个新的提交git commit -m'remove landed。 mov

  • 我切换回主人 - >他警告我,我会放弃对此提交的更改,为什么不创建新分支? - >所以我创建了新的分支固定电影

  • ,最后我重新将分支集成到主分支中,希望它能修复我的大文件问题。 b


    和yes ..显然它没有固定任何东西 - 因为在他重新删除这个文件之前,他仍然想先推送有问题的提交。 。

    欢迎任何帮助,非常欢迎!因为唯一留在我脑海的是 - 创建一个新的回购..丢失所有提交..并再次手动重新进行所有更改..

    解决方案

    您可以执行交互式重定位并修复将不需要的文件移除到您添加它的提交中的提交。这将基本上保留原始提交,就好像文件从未被添加一样。



    从命令行(您需要提交/存储任何更改):

      git rebase -i origin / master 

    您将看到一个文本编辑器,您可以在其中从上到下操作您所做的提交。移动remove ...提交,以便它直接位于_MOJ-1120 ...提交之后。将选择更改为 fixup ,保存并退出。



    如果这不符合你的要求,你可以使用git reflog回到你之前的位置。您可能希望在完成此操作之前写下当前的SHA,以使其更容易。


    I've found this wonderful help-page of git:

    https://help.github.com/articles/working-with-large-files/

    and both approaches are not working for me... i think because the big-file i trying to get rid of is not in the latest commit and i was not able to push yet... but in the latest state, i already removed the file.. and this delete is also not pushed yet..

    so this is what it looks like:

    • in the selected revision i accidently added the big-stupid .mov file
    • two commits later i've removed it

    and as you can see i already tried out a thing:

    • i switched back to the revision just after i've added the file "git checkout blabla"
    • i deleted the file "git rm /assets/video/landed.mov"
    • i made a new commit "git commit -m 'removed landed.mov"
    • i switched back to master -> he's warning me that i will loose my change from this commit, why not creating a new branch? -> so i created new branch "fixing-movie"
    • and finally i re-integrated the branch into master, hoping it will fix "somehow" my large file issue

    and yes.. obviously it fixed nothing - because he still wants to push the problematic commit first before he gets into all my deletions of this file again...

    any help welcome, extremely welcome! because the only thing left in my mind is - creating a new repo.. loosing all commits.. and hacking in all the changes manually again..

    解决方案

    You can do an interactive rebase and 'fix-up' the commit that removed the unwanted file into the commit in which you added it. This will essentially leave the original commit as though the file was never added.

    From the command line (you need to commit/stash any changes):

    git rebase -i origin/master
    

    You'll be presented with a text editor in which you can manipulate the commits you made, from top to bottom. Move the "removed..." commit up so that it comes directly after the _"MOJ-1120..." commit. Change the pick to fixup, save the file and exit.

    If this doesn't do what you want, you can use the git reflog to go back to where you were beforehand. You may like to write down the current SHA before doing this to make it easier.

    这篇关于从git中删除一个文件,它尚未推送,但也没有在最新的提交?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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