如果文件内容保持不变,则使git忽略修改日期更改 [英] Make git ignore modification date changes if the content of the file stays the same

查看:744
本文介绍了如果文件内容保持不变,则使git忽略修改日期更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有python脚本,可以生成和修改不同的xml文件.他们的工作方式是打开文件,基于该文件创建ElementTree对象,并在必要时尝试修改对象的内容,然后将这些对象保存到原始文件中.

I have python scripts which generate and modify different xml-files. They work so that they open a file, create an ElementTree object based on it, try to modify object's content if necessary and than save those objects into origin files.

问题是,有时它们甚至根本不会更改文件的内容.但是文件的修改日期会更改.

The thing is that sometimes they don't change the content of the file even a bit. But file's modification date changes.

Git则将那些文件视为已更改",因为它注意到修改日期已更改.尽管它不会造成差异(显然).

Git, on the other hand, treats those file as "changed" because it notices that modification date has changed. Although it won't make diffs (obviously).

citool 行为疯狂(提示日期已更改,但文件本身未更改,请尝试对其进行重新扫描,然后再次将其显示为已修改")

citool acts crazy (alerts that date has changed but the file itself hasn't, tries to rescan them and once again shows them as "modified")

我无权修改这些python脚本,因此无法重写它们(它们已存储并经常在单独的存储库中进行修改).有什么办法告诉git忽略特定文件夹的修改日期更改?看到数十个更改的"文件,而实际上只有其中一个真正被修改,这真是令人讨厌.

I do not have access to modify those python scripts so rewriting them is not an option (they are stored and frequently modified in a separate repo). Is there any way to tell git to ignore modification date changes for a specific folder? It's just very annoying seeing dozens of "changed" files when in fact only one of them was really modified.

我知道我可以暂存所有文件,然后取消暂存它们,但是我想省略一些额外的操作.有时它只会干扰正常的git工作流程.

I know I can stage all the files and then unstage them but it takes a couple of extra actions I would like to omit. And sometimes it just interferes with normal git workflow.

更新:git citool错误读取(引用):未检测到差异.< file>没有更改.此文件的修改日期已由另一个应用程序更新,但是文件未更改.重新扫描将自动开始,以查找其他可能具有相同状态的文件."

Update: git citool error reads (quote): "No differences detected. <file> has no changes. The modification date of this file was updated by another application, but the content within the file was not changed. A rescan will be automatically started to find other files which may have the same state."

然后在重新扫描之后,所有伪造的文件再次出现.

Then after rescan all fake-modified files appear again.

git status 还将这些文件显示为已修改"

git status also shows those files as "modified"

推荐答案

您可以对所有受影响的文件执行git add,之后它将停止显示它们在git status中的修改状态(并且实际上不会暂存它们以进行提交)如果没有更改).至少对我有用(我正在使用git 2.8.1).

You can do git add for all affected files, after that it stops displaying them as modified in git status (and doesn't actually stage them for commit if there are no changes). At least that worked for me (I'm using git 2.8.1).

这篇关于如果文件内容保持不变,则使git忽略修改日期更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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