See " Preserve git --assume-unchanged files between branch checkouts "
git update-index --skip-worktree -- path
That wouldn't be reverted from a git stash
.
Original answer
From "temporarily ignoring files ":
git update-index --assume-unchanged <file>
That would allow to ignore changes to that specific files.
This won't help if you want to revert code changes while keeping config changes in the same file though.
And git stash will still revert it: How to prevent git stash dropping changes to files with the "assume unchanged" bit?
Note that, before Git 2.25 (Q1 2020), "git stash
save" in a working tree that is sparsely checked out mistakenly removed paths that are outside the area of interest.
See commit 4a58c3d, commit 8dfb04a (30 Oct 2019) by Johannes Schindelin (dscho
).
(Merged by Junio C Hamano -- gitster
-- in commit 57b5301, 10 Nov 2019)
stash
: handle staged changes in skip-worktree files correctly
Signed-off-by: Johannes Schindelin
When calling git stash
while changes were staged for files that are marked with the skip-worktree
bit (e.g. files that are excluded in a sparse checkout), the files are recorded as deleted instead.
The reason is that git stash
tries to construct the tree reflecting the worktree essentially by copying the index to a temporary one and then updating the files from the worktree.
Crucially, it calls git diff-index
to update also those files that are in the HEAD but have been unstaged in the index.
However, when the temporary index is updated via git update-index --add --remove
, skip-worktree entries mark the files as deleted by mistake.
Let's use the newly-introduced --ignore-skip-worktree-entries
option of git update-index
to prevent exactly this from happening.
Note that the regression test case deliberately avoids replicating the scenario described above and instead tries to recreate just the symptom.
Reported by Dan Thompson.