简体   繁体   English

如何从本地提交中删除一个不是我最后一次提交的文件

[英]how to remove a file from local commit which is not my last commit

I have incorrectly added a zip file to one of my commits which is not the last commit. 我错误地将一个zip文件添加到我的一个提交中,这不是最后一次提交。 It is a big file and I get stuck when I try to push these changes to server, because git tries to push the file on remote branch. 这是一个大文件,当我尝试将这些更改推送到服务器时,我遇到了困难,因为git尝试将文件推送到远程分支上。

How can I remove this particular file. 如何删除此特定文件。

A --> B --> C --> D --> E --> F

my remote is at A and I incorrectly added file in commit C and now I'm at commit F. 我的遥控器在A,我在提交C中错误地添加了文件,现在我在提交F.

When I do 当我做

git log --name-only

it shows me this file link which I have deleted manually. 它显示了我手动删除的文件链接

You can use an interactive git rebase -i as described here: Git-Tools-Rewriting-History . 您可以使用交互式git rebase -i如下所述: Git-Tools-Rewriting-History This way you'll create 4 new commits (C', D', E', F') and the original commits will be deleted. 这样你就可以创建4个新的提交(C',D',E',F'),原始提交将被删除。 If you've not pushed the changes anywhere outside your local git repository then it is okay, otherwise you haven't to do that at all costs! 如果您没有将更改推送到本地git存储库之外的任何位置,那么它是可以的,否则您不必不惜一切代价这样做!

git rebase -i HEAD~20 // rebase the last 20 commits git rebase -i HEAD~20 //最后20次提交

// a list of commits will show //将显示提交列表

//go to the proper commit and type 'edit' then hit "Enter" on you keyboard //转到正确的提交并输入'edit',然后在键盘上点击“Enter”

I am assuming you are using nano and not vim 我假设你使用nano而不是vim

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

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