如何忽略git中的文件或目录,无论它是已跟踪,未跟踪甚至是提交的一部分 [英] How to ignore a file or directory in git, be it tracked, untracked or even part of commit

查看:91
本文介绍了如何忽略git中的文件或目录,无论它是已跟踪,未跟踪甚至是提交的一部分的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想完全忽略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...

  1. 将文件/图案添加到.gitignore文件
  2. 从存储库中删除不需要的文件
  3. 提交取消跟踪不需要的文件并提交.gitignore
  4. 推送更改
  1. add the file/pattern to the .gitignore file
  2. delete the unwanted files from the repository
  3. commit to untrack the undesired file and commit .gitignore
  4. 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 adds of those files (unless --forced)

这篇关于如何忽略git中的文件或目录,无论它是已跟踪,未跟踪甚至是提交的一部分的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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