我怎样才能让git忽略未来版本的修改? [英] How can I make git ignore future revisions to a file?

查看:92
本文介绍了我怎样才能让git忽略未来版本的修改?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了包含在git存储库中的文件的默认版本。重要的是,当有人克隆存储库时,他们会获得该文件的副本。但是,我想设置git,以便稍后忽略此文件的更改。 .gitignore 仅适用于未跟踪的文件。



我的动机是该文件包含特定于计算机的信息。我希望提供默认值,同时允许人们进行本地更改,但不会将其推回原始存储库,并在我们提出新更改时创建合并冲突。



我们一般很懒,并且使用 git add。很多,所以我很确定如果我不能让git忽略这个文件,对它的更改将会结束
$ b 总之,


  1. 我希望创建一个文件,将其称为 default_values.txt ,并将其添加到我的git存储库中,并在有人克隆该存储库时包含它。
  2. code> git add。不应该添加 default_values.txt 到提交中。
  3. 行为应该传递给存储库的任何克隆。


解决方案

像其他人提到的一样,一个好的现代解决方案是: b
$ b

  git update-index --skip-worktree default_values.txt 

这将忽略对本地和上游文件的更改,直到您决定再次允许它们:

  git update-index --no-skip-worktree default_values.txt 

您可以获得跳过标记的文件列表:

  git ls-files -v。 | grep ^ S 

请注意,与--skip-worktree不同,--assume-unchanged状态将得到一旦上游变更被撤销,就会失去。

I have created a default version of a file included in a git repository. It's important that when someone clones the repository, they get a copy of this file. However, I would like to set git so that it ignores changes to this file later. .gitignore works only on untracked files.

My motivation is that this file contains machine-specific information. I would like to provide default values, while allowing people to make local changes that won't get pushed back to the origin repository, creating merge conflicts when we pull new changes.

We are generally pretty lazy and use git add . a lot, so I'm pretty sure if I can't tell git to ignore this file, changes to it will end up getting committed and pushed.

To summarize,

  1. I would like to create a file, call it default_values.txt that is added to my git repository and is included when someone clones that repository.
  2. git add . should not add default_values.txt to the commit.
  3. This behavior should be passed on to any clones of the repository.

解决方案

As many others have mentioned, a good modern solution is:

git update-index --skip-worktree default_values.txt

That will ignore changes to that file, both local and upstream, until you decide to allow them again with:

git update-index --no-skip-worktree default_values.txt

You can get a list of files that are marked skipped with:

git ls-files -v . | grep ^S

Note that unlike --skip-worktree, the --assume-unchanged status will get lost once an upstream change is pulled.

这篇关于我怎样才能让git忽略未来版本的修改?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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