Git-暂时忽略对文件的微不足道的更改 [英] Git - Temporarily ignore trivial changes to files

查看:74
本文介绍了Git-暂时忽略对文件的微不足道的更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在寻找一种隐藏"对Git中的几个文件进行的较小更改的方法,以便在对这些文件进行其他更改之前,它们不会以git状态显示.

I'm looking for a way to 'hide' minor changes made to a few files in Git, such that they will not show up in git status until a different change is made to those files.

示例:我有一个java文件,唯一的更改是删除了未使用的导入(贡献者在提交之前忘记了运行organization导入).现在,我删除了该导入,更改(显然)显示在git中.由于我对该文件没有其他更改,因此我真的不喜欢将文件作为另一个(不相关的)更改的一部分提交或独立提交此更改.当然,我可以还原更改,并且仅在需要对该文件进行更改时才应用该更改,但是我可能会冒着风险"将其忘记.

Example: I have a java file where the only change made is the removal of an unused import (a contributor forgot to run an organize imports before committing). Now I have removed that import and the change (obviously) shows up in git. Since I have no other change to make to that file, I don't really like committing the file as part of another (unrelated) change or committing this change stand-alone. Sure, I could revert the change and only applying it whenever I will have to make changes to that file, but I could "risk" forgetting it.

是否存在用于此类任务的命令?它会像假定不变的命令那样工作,但不是永久的.

Does a command exists for such a task? It would work somewhat like the assume-unchanged command but in a not permanent way.

如果没有这样的命令可用,正确的解决方法是什么?

What would be the proper way to resolve this if no such command is available?

谢谢.

推荐答案

在我的用例中(使用个人计算机上已编辑的配置文件在配置不变的另一台计算机上运行开发),这是我的解决方案:

In my use case (developing using an edited config file on my personal machine, running on another machine with the unchanged config), this was the solution for me:

开始忽略对文件的更改:

start ignoring changes to a file:

git update-index --assume-unchanged path/to/file

再次保持跟踪:

git update-index --no-assume-unchanged path/to/file

这篇关于Git-暂时忽略对文件的微不足道的更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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