Git忽略&改变过去 [英] Git ignore & changing the past

查看:112
本文介绍了Git忽略&改变过去的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近只添加了一个 .gitignore 文件来忽略我的子目录中的某些特定数据文件。我真的很想回到过去,并将它们从以前的提交/历史记录中删除。

这是否容易完成?

解决方案

这将是一个两步骤的过程:



引入.gitignore文件



为此,早​​期的提交必须有 .gitignore 文件。所以,你需要:


  1. 检查root提交: git checkout -b temp $(git rev-列表HEAD | tail -1)

  2. 添加 .gitignore 文件。 $ b
  3. git commit --amend

  4. 将所有现有分支重新映射到temp。这可能会或可能不会无缝工作,所以如果出现任何冲突,您可能需要摆弄它。


  5. 改写历史记录

    现在您可以通过以下命令自动从所有分支中删除这些文件:

    git filter-branch --tree-filter'git clean -f -X' - --all



    这会重写所有的分支删除被忽略的文件。取决于您的存储库的大小,可能需要一段时间。

    I only recently added a .gitignore file to ignore some specific data files in a subdirectory of mine. I'd really like to go back in time and remove them from previous commits/history as well.

    Is this easily accomplished? Where/how should I start?

    解决方案

    This will be a two-step procedure:

    Introduce the .gitignore file

    For this to work, the early commits are going to have to have your .gitignore file. So, you need to:

    1. Check out the root commit: git checkout -b temp $(git rev-list HEAD | tail -1)
    2. Add the .gitignore file.
    3. git commit --amend
    4. Rebase all of your existing branches onto "temp". This may or may not work seamlessly, so you might need to fiddle with it if any conflicts spring up.
    5. Check out your working branch and delete the temp branch.

    Rewrite history

    Now you can automatically remove these files from all of the branches by this command:

    git filter-branch --tree-filter 'git clean -f -X' -- --all

    This will rewrite all of your branches to remove ignored files. It may take a while depending on the size of your repository.

    这篇关于Git忽略&改变过去的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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