Git 忽略少数文件更新本地(不是 .gitignore)

Git update local ignoring few files (is not .gitignore)

Scenario:
 Bitbucket:
  file1 
  file2 
  file3  

 Local:
  file1 - person1 is working on it
  file2 - person2 is working on it
  file3 - common with personal hardcoded configuration
  untracked files

person1 提交并推送他对 file1 的更改。 person2 如何在不重置 file2、file3 和未跟踪文件的情况下更新本地的 file1? 我尝试这样做已经有一段时间了,但我仍然找不到简单的方法! 谢谢

当您从远程存储库获取新提交时,未跟踪的文件将不会更新。至于 file2file3(我假设 跟踪),您需要在它们上设置 skip-worktree 标志。这样 Git 就不会在您的工作目录中更新它们。

来自documentation:

--[no-]skip-worktree
When one of these flags is specified, the object name recorded for the paths are not updated.

更多specifically:

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.

您可以使用 git-update-index 命令在特定文件上设置 skip-worktree 标志:

git update-index --skip-worktree path/to/file2

如果您稍后想取消设置标志,请改用 --no-skip-worktree 选项:

git update-index --no-skip-worktree path/to/file2