在git中合并配置文件

在git中合并配置文件,git,github,Git,Github,我有一个包含配置文件的github存储库 我克隆存储库以创建实例并编辑配置文件 当我需要拉取最新版本时,我会隐藏配置文件,然后在拉取后弹出它们 但是,有时会更改存储库配置文件。这意味着本地配置文件需要合并到存储库版本中,但不应将此合并文件推回存储库 如何执行此操作?合并完成后(但尚未分段),您可以尝试使用: 从索引中看不到任何更改 (稍后的git更新索引--不假设未更改--您的配置文件)弹出后,应该会自动合并 问题是,当git完成自动合并时,它可能已经将文件标记为“需要提交”。事实上,您所问的是

我有一个包含配置文件的github存储库

我克隆存储库以创建实例并编辑配置文件

当我需要拉取最新版本时,我会隐藏配置文件,然后在拉取后弹出它们

但是,有时会更改存储库配置文件。这意味着本地配置文件需要合并到存储库版本中,但不应将此合并文件推回存储库

如何执行此操作?

合并完成后(但尚未分段),您可以尝试使用:

从索引中看不到任何更改


(稍后的
git更新索引--不假设未更改--您的配置文件)

弹出后,应该会自动合并

问题是,当git完成自动合并时,它可能已经将文件标记为“需要提交”。事实上,您所问的是如何“重置”此标记?解决方案是:

git reset --mixed HEAD
从手册页:

   git reset [<mode>] [<commit>]
       This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>. If <mode> is omitted,
       defaults to "--mixed". The <mode> must be one of the following:

    [...]

       --mixed
           Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.
git重置[]
此表单将当前分支头重置为,并可能根据需要更新索引(将其重置为的树)和工作树。如果省略,
默认为“-mixed”。必须是以下内容之一:
[...]
--混合的
重置索引,但不重置工作树(即保留更改的文件,但不标记为提交),并报告未更新的内容。这是默认操作。

正如您所看到的,
——可以使用混合的
,因为它是默认模式。

以编程方式处理这个问题可能会更好—有一个包含默认值的配置文件,但允许使用本地的、未提交的覆盖文件,并在将配置加载到应用程序时合并配置。@cmbuckley这是个好主意。但是,这会增加每个页面加载的处理量。我可以通过缓存配置来解决这个问题。
   git reset [<mode>] [<commit>]
       This form resets the current branch head to <commit> and possibly updates the index (resetting it to the tree of <commit>) and the working tree depending on <mode>. If <mode> is omitted,
       defaults to "--mixed". The <mode> must be one of the following:

    [...]

       --mixed
           Resets the index but not the working tree (i.e., the changed files are preserved but not marked for commit) and reports what has not been updated. This is the default action.