如何在 git 中保留假设未更改的文件的同时重置我的提交?

How can I reset my commits while keeping my assume-unchanged files in git?

我有很多文件设置为

git update-index --assume-unchanged <file>

在某些情况下,我的分支被搞乱并与 origin/master 分道扬镳。比方说

and have 4 and 8 different commits each, respectively.

所以我想恢复我所有的提交并保持对 origin/master 的更新,同时保持我假设未更改的文件不被刷新。 我该怎么做?

您可以尝试使用 --skip-worktreegit update-index

而不是使用 --assume-unchanged

带有标志 git update-index --skip-worktree 的文件应该抵抗 git reset(这将从索引中取消任何添加的更改)

你可以看到一个full analysis of the differences between --assume-unchanged and --skip-worktree here.

It looks like --skip-worktree is trying very hard to preserve your local data. But it doesn’t prevent you to get upstream changes if it is safe. Plus git doesn’t reset the flag on pull.
But ignoring the 'reset --hard' command could become a nasty surprise for a developer.