Can git-stash ignore modifications to a tracked file

I am working on a project which has a bit of an uncommon behaving thing:

One of the files in the source code is a file that contains serious code, but it can edit itself to also include some configuration. Whether this is good design is a different discussion, but to be able to test my project, this file needs to be in its modified state.

Before I commit anything, I normally do an A-B comparison between the situation before and after my contribution. I use git stash to switch between base and my dirty working copy. The problem is that when using git stash, it also reverts my config-thing.

My current workaround is cumbersome: I do a git add path/to/settingsfile and then git stash --keep-index, but I rather dislike this workaround. Is there a more elegant solution to have git ignore all modifications to this file unless I specify otherwise?

  • How to ignore a file or directory in git, be it tracked, untracked or even part of commit
  • Which file does svn:ignore modify?
  • How can I ignore whitespace in the NetBeans merge tool
  • git update-index --assume-unchanged returns error
  • How does Perforce ignore file syntax differ from gitignore syntax?
  • git diff: ignore renaming of variables
  • how to implement something like a VCS status/ignore program?
  • How can always ignore a file while merge
  • One Solution collect form web for “Can git-stash ignore modifications to a tracked file”

    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?

    Git Baby is a git and github fan, let's start git clone.