简体   繁体   English

从git删除文件,该文件还没有被推送,但是也没有在最新提交中?

[英]Remove a file from git which is not pushed yet but also not in latest commit?

I've found this wonderful help-page of git: 我发现了这个很棒的git帮助页面:

https://help.github.com/articles/working-with-large-files/ 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 在选定的版本中,我不小心添加了大笨拙的.mov文件
  • 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" 添加文件“ git checkout blabla”后,我又切换回了修订版
  • i deleted the file "git rm /assets/video/landed.mov" 我删除了文件“ git rm /assets/video/landed.mov”
  • i made a new commit "git commit -m 'removed landed.mov" 我做了一个新的提交“ 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? 我切换回master->他警告我,我将放弃这次提交的更改,为什么不创建一个新分支? -> so i created new branch "fixing-movie" ->所以我创建了新的分支“ fixing-movie”
  • and finally i re-integrated the branch into master, hoping it will fix "somehow" my large file issue 最后,我将分支重新整合到master中,希望它可以“以某种方式”解决我的大文件问题

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. 向上移动“已删除...”提交,以便它紧接在提交“ _MOJ-1120 ...”之后。 Change the pick to fixup , save the file and exit. pick更改为fixup ,保存文件并退出。

If this doesn't do what you want, you can use the git reflog to go back to where you were beforehand. 如果这样做不能满足您的要求,则可以使用git reflog返回到您之前的位置。 You may like to write down the current SHA before doing this to make it easier. 您可能希望先写下当前的SHA,以使其更容易。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM