Git:忽略版本控制的文件

编程入门 行业动态 更新时间:2024-10-13 02:21:17
本文介绍了Git:忽略版本控制的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

.gitignore文件在忽略一些我们不想控制的文件时非常有用。不幸的是,当文件已经受版本控制时,它不能使用。例如,我的.gitignore(已经添加到git中)文件可能与我的同事想要的文件不同(例如,我想忽略Vim文件)。每当我对这个文件进行更改时,git都会将其显示为修改后的文件。所以我的问题:

  • 有什么办法可以忽略某个已经由Git控制的文件的变化吗?!
  • 有什么办法可以提交这些更改,但只保留给我自己吗?显然,我不想使用分支,因为我正在某个分支上工作。
  • >

    如果要排除特定于进程的文件(如Vim临时文件),请编辑(本地)文件 .git / info / exclude 和在那里添加排除模式。此文件专为特定于开发人员的排除而设计,而不是 .gitignore ,该文件专为项目范围的排除项目而设计。

    简短的总结是,每个人都应该对添加到 .gitignore 的内容达成一致。对于您不同意的文件,请使用 .git / info / exclude 。

    The .gitignore file is very useful in ignoring some of the files that we don't want to control. Unfortunately, it cannot be used when the file is already under version control. For example, my .gitignore (which is already added to git) file might be different than what my coworker wants it to be (e.g. I want to ignore Vim files). Whenever I make changes to this file, git shows it as a modified file. So my questions:

  • Is there any way to ignore changes for a certain file, which is already controlled by Git?!
  • Is there any way to commit these changes, but keep it for myself only? Obviously, I don't want to use a branch, because I am working on a certain branch.
  • 解决方案

    If you want to exclude files that are specific to your process (such as Vim temporary files), edit the (local) file .git/info/exclude and add your exclusion patterns there. This file is designed for developer-specific exclusions rather than .gitignore, which is designed for project-wide exclusions.

    The short summary is, everybody should agree on what is added to .gitignore. For files where you don't agree, use .git/info/exclude.

    更多推荐

    Git:忽略版本控制的文件

    本文发布于:2023-10-31 10:50:41,感谢您对本站的认可!
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:版本   文件   Git

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!