如何告诉 Git 忽略自上次 staged/commit 以来文件中发生的更改?
How to tell Git to ignore what has been changed in a file since the last staged/commit?
我不想撤消更改。
我不想 Git 忽略这个文件。
(注:纯属假设情况,以说明问题。)
我是一个没有经验的程序员,我硬编码了一个用于计算价格的日期。所以今天我更改了那个日期,运行 代码,当然,Git 跟踪了更改。我想在下次 运行 这段代码时看到那个日期,所以我不想撤消更改。
我如何告诉 Git 忽略该更改,因为 staging/committing 等没有任何意义?
当然,如果我进行了其他代码更改,那么我确实希望 Git 进行跟踪。
换句话说,如何告诉Git我自上次stage/commit以来所做的更改是ignored/forget it/you没看到?
无法忽略 Git 中的跟踪文件。 Git FAQ is very clear about this。它具体说:
Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.
It’s tempting to try to use certain features of git update-index
, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.
Git 常见问题解答针对这种情况的建议是将提交的部分存储在文件中的不同位置,然后默认使用脚本将该值复制到其预期位置,该位置将被忽略.然后,您可以修改被忽略的文件以具有您喜欢的任何值,而无需忽略它。
我不想撤消更改。 我不想 Git 忽略这个文件。
(注:纯属假设情况,以说明问题。)
我是一个没有经验的程序员,我硬编码了一个用于计算价格的日期。所以今天我更改了那个日期,运行 代码,当然,Git 跟踪了更改。我想在下次 运行 这段代码时看到那个日期,所以我不想撤消更改。
我如何告诉 Git 忽略该更改,因为 staging/committing 等没有任何意义?
当然,如果我进行了其他代码更改,那么我确实希望 Git 进行跟踪。
换句话说,如何告诉Git我自上次stage/commit以来所做的更改是ignored/forget it/you没看到?
无法忽略 Git 中的跟踪文件。 Git FAQ is very clear about this。它具体说:
Git doesn’t provide a way to do this. The reason is that if Git needs to overwrite this file, such as during a checkout, it doesn’t know whether the changes to the file are precious and should be kept, or whether they are irrelevant and can safely be destroyed. Therefore, it has to take the safe route and always preserve them.
It’s tempting to try to use certain features of
git update-index
, namely the assume-unchanged and skip-worktree bits, but these don’t work properly for this purpose and shouldn’t be used this way.
Git 常见问题解答针对这种情况的建议是将提交的部分存储在文件中的不同位置,然后默认使用脚本将该值复制到其预期位置,该位置将被忽略.然后,您可以修改被忽略的文件以具有您喜欢的任何值,而无需忽略它。