Git忽略&改变过去 [英] Git ignore & changing the past
问题描述
我最近只添加了一个 .gitignore
文件来忽略我的子目录中的某些特定数据文件。我真的很想回到过去,并将它们从以前的提交/历史记录中删除。
这是否容易完成?
这将是一个两步骤的过程:
引入.gitignore文件
为此,早期的提交必须有 .gitignore
文件。所以,你需要:
- 检查root提交:
git checkout -b temp $(git rev-列表HEAD | tail -1)
- 添加
.gitignore
文件。 $ b -
git commit --amend
- 将所有现有分支重新映射到temp。这可能会或可能不会无缝工作,所以如果出现任何冲突,您可能需要摆弄它。
- Check out the root commit:
git checkout -b temp $(git rev-list HEAD | tail -1)
- Add the
.gitignore
file. git commit --amend
- 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.
- Check out your working branch and delete the temp branch.
改写历史记录
现在您可以通过以下命令自动从所有分支中删除这些文件:
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:
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屋!