从Git Repo中删除现有的文件 [英] Remove an Existing File from a Git Repo

查看:155
本文介绍了从Git Repo中删除现有的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想让git停止在我们的仓库中跟踪我的本地开发日志(log / development.log)。这是可能的,我该怎么做?

解决方案

只需一次给出完整答案:

$来自klemens的b
$ b


  1. :您需要将文件添加到您的 .gitignore 文件回购中不需要的文件。即

    $ cd
    $ cat >> .gitignore
    development.log
    Cd


  2. 来自m。 narebski:然后你需要通过执行 git rm --cached< file> 然后提交这个删除文件来移除该文件。


如果您还希望将回购看起来好像从未跟踪过该文件那样,那会更加复杂且极度灰心,因为它不会只会为您的历史记录中的每一次提交创建全新的提交,从而破坏克隆您的repo的其他人之间的恶意互操作性,但也会使每个提交都未经测试(假设您在提交之前测试提交)。

考虑到这个警告,如果这是您的目标,您正在寻找的工具是 filter-branch 。第一个例子正是我所描述的。


I want git to stop tracking my local development log (log/development.log) in our repositories. Is this possible and how can I do it?

解决方案

Just to give the full answer all at once:

  1. from klemens: You need to add the file to your .gitignore file somewhere above the undesired file in the repo. i.e.

    $ cd $ cat >> .gitignore development.log C-d

  2. from m. narebski: You then need to remove the file from the repo by executing "git rm --cached <file> and then committing this removal"

If you were also hoping to make the repo look as if it had never tracked that file, that is much more complicated and highly discouraged as it not only creates brand new commits for every single commit in your history, thus destroying interoperability in a nasty way between other people who have cloned your repo, but it also leaves every one of those commits untested (assuming you test your commits before making them).

With that caveat in mind, the tool you're looking for if that's your goal is filter-branch. The first example does exactly what I'm describing.

这篇关于从Git Repo中删除现有的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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