Take a look at this answer from @Borealid to the question Git - Difference Between 'assume-unchanged' and 'skip-worktree'.
It looks like using the skip-worktree
flag is a good way to solve my problem. I got to your problem by looking for an answer to my problem, and I think they are essentially the same problem. However, using the skip-worktree
flag, you still need to pay attention when performing certain operations and the file has changed either locally or on the remote.
Prior to learning about the skip-worktree
flag, the best solution I could come up with is to use a combination of .gitignore
plus an alias for git clean
. It is a bit of a hack, but if your only option is to use the exclude option with git clean
, then this may help.
- Add a consistent and unique prefix and/or postfix to any files you are modifying and do not want to commit. For example, add
myusername.
to the beginning of the filename.
- Always use
git clean -dx --exclude=myusername.*
(make an alias for this).
- Write a script that recursively walks your files and copies files beginning with
myusername.
to files without myusername.
.
Now, whenever you run cleanup, the files with the desired/true filename are going to get cleaned, but you can restore them by running the script. Also, treat the files with the true filename as readonly. Always edit the files with the kludged filenames and then run the script.
Combining these might also work to mitigate the edge cases when using the skip-worktree
flag.