git push after removing large file

后端 未结 2 1999
礼貌的吻别
礼貌的吻别 2021-02-04 18:43

I accidentally commited log/test.log but have never pushed it. I have since done a git rm to get rid of it. But when I try to push, I\'m still getting a huge amount of data at

2条回答
  •  情歌与酒
    2021-02-04 19:46

    If you haven't pushed, you can use git rebase -i to edit your commit history, removing both the add and the rm. The one caveat is that you have to be careful not to edit any commits that have already been pushed.

    http://blog.madism.org/index.php/2007/09/09/138-git-awsome-ness-git-rebase-interactive

    You asked whether you can still do this if there are other changes in the commit and other commits following this one. It depends. You should be able to edit/remove any unpushed commit, not just the most recent. But the rebase might fail if later changes depended heavily on changes in the deleted commit (e.g., you added a file, then edited it in a later commit). If you delete a commit, you will lose all of the changes in that commit. I don't know of a way to remove a single change from a commit. If you don't want to lose the other changes in the test.rb commit, you could generate a patch (with git show > /tmp/patch or with the built-in git patch features) before deleting the commit. Then edit your patch file to remove the large test.rb, but leave your desired changes, and reapply the patch to the head.

    If you have the problem I mentioned earlier where rebase fails (or you think it would fail), you could save patches for all of your commits after the problem commit, delete them all, and reapply them in order.

提交回复
热议问题