如何忽略git中的文件或目录,无论它是已跟踪,未跟踪甚至是提交的一部分 [英] How to ignore a file or directory in git, be it tracked, untracked or even part of commit
问题描述
我想完全忽略git存储库的一部分.当前在存储库中跟踪该目录,我想确保
I want to completely ignore a part of a git repository. The directory is currently tracked in the repository and I'd like to ensure that
- 任何人在上游存储库中更改其内容时,即使我的副本也被更改,我也不会遇到任何合并冲突.
- 每当我更改其内容时,我所做的任何提交都不会反映这些更改
我不太在乎实际内容.
问题是在构建过程中自动生成的文件引起的.不幸的是,有人偶然将它们提交到存储库中,但是它们在与创建者不同的机器上使用时,由于路径不同等原因会导致构建错误,从而导致令人讨厌的合并冲突.
The problem arises with files automatically generated during build. Unfortunately, someone happened to commit them to the repository, but they cause build errors due to different paths etc. when used on different machine than their creator and consequently nasty merge conflicts.
AFAIK,.gitignore
不适用于此目的,因为它仅适用于未跟踪的文件.
AFAIK, .gitignore
won't work for this purpose, as it only applies to untracked files.
推荐答案
如果该文件永远不会进入存储库,请解决此问题并正确执行...
If the file is supposed to never get into the repository, fix the problem and do it correctly...
- 将文件/图案添加到
.gitignore
文件 - 从存储库中删除不需要的文件
- 提交取消跟踪不需要的文件并提交
.gitignore
- 推送更改
- add the file/pattern to the
.gitignore
file - delete the unwanted files from the repository
- commit to untrack the undesired file and commit
.gitignore
- push the changes
您将不必再处理那些不需要的文件,因为.gitignore
会避免以后再使用这些文件的git add
(除非--force
d)
And you'll never have to deal with those unwanted files again because .gitignore
will avoid future git add
s of those files (unless --force
d)
这篇关于如何忽略git中的文件或目录,无论它是已跟踪,未跟踪甚至是提交的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!