gpt4 book ai didi

git - 暂时 stash git中一些更改的文件

转载 作者:太空狗 更新时间:2023-10-29 13:52:48 26 4
gpt4 key购买 nike

每当我做一个工作任务时,我都会在git中创建一个本地分支,然后我需要在实际工作之前修改一堆配置文件(主要包含数据库的连接字符串)以设置为我的本地环境。我不想在完成任务后将这些更改推送到存储库。

实际上,我更愿意在查看更改的文件时将它们过滤掉 (git status)。

我可以先提交到我的本地分支并在推送之前恢复它。但我有可能忘记它。有更好的方法吗?

最佳答案

最推荐的解决方案是使用:

git update-index --skip-worktree <file>

Documentation :

--[no-]skip-worktree

When one of these flags is specified, the object name recorded for the paths are not updated. Instead, these options set and unset the "skip-worktree" bit for the paths. See section "Skip-worktree bit" below for more information.

还有 skip-worktree bit :

Skip-worktree bit

Skip-worktree bit can be defined in one (long) sentence: When reading an entry, if it is marked as skip-worktree, then Git pretends its working directory version is up to date and read the index version instead.

To elaborate, "reading" means checking for file existence, reading file attributes or file content. The working directory version may be present or absent. If present, its content may match against the index version or not. Writing is not affected by this bit, content safety is still first priority. Note that Git can update working directory file, that is marked skip-worktree, if it is safe to do so (i.e. working directory version matches index version)

Although this bit looks similar to assume-unchanged bit, its goal is different from assume-unchanged bit’s. Skip-worktree also takes precedence over assume-unchanged bit when both are set.

--assume-unchanged 标志用于提高性能,而 --skip-worktree 用于您确实更改文件并希望 git无论如何跳过它。

要撤消,请使用:

git update-index --no-skip-worktree <file>

关于git - 暂时 stash git中一些更改的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45006289/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com