代码之家  ›  专栏  ›  技术社区  ›  Rob Wilkerson

删除一个我不应该提交给Git的文件

git
  •  4
  • Rob Wilkerson  · 技术社区  · 15 年前

    在进行一系列更改的过程中,我意识到一个意外的文件偷偷地变成了一两个提交。因为直到后来我才意识到这一点,所以包含该文件的提交现在已被推送到远程。我需要提交,我只想从中删除此特定文件。

    当然,我需要做的是深入我的树的每个角落(本地和远程)并删除该文件。我试过一些方法 filter-branch filter-tree ,但当我尝试推动更改时,将被拒绝。

    谢谢。

    更新

    在max的要求下,以下是我在尝试推送时得到的消息:

    $ git push origin develop
    To git@codaset.com:robwilkerson/cakephp-polyclip-plugin.git
    ! [rejected]        develop -> develop (non-fast-forward)
    error: failed to push some refs to 'git@codaset.com:robwilkerson/cakephp-polyclip-plugin.git'
    To prevent you from losing history, non-fast-forward updates were rejected
    Merge the remote changes before pushing again.  See the 'Note about fast-forwards' section of 'git push --help' for details.
    
    3 回复  |  直到 15 年前
        1
  •  2
  •   Bastian    15 年前

    你在git push中添加了-f(force)吗?没有这个标志,就不能覆盖“旧”提交。

    -f, --force
           Usually, the command refuses to update a remote ref that is not an
           ancestor of the local ref used to overwrite it. This flag disables
           the check. This can cause the remote repository to lose commits;
           use it with care.
    

    如果其他人已经从存储库中取出,它可能会变得混乱。

        2
  •  10
  •   Petros    15 年前

    a nice guide 在GitHub,那可能会对你有帮助。

        3
  •  0
  •   stefanB    15 年前

    然后,当它们与您进行更改的版本同步时,它应该传播到每个分支。