0

Can I tell Git to ignore changes in some tracked file when commiting a folder? So that, for example, if I decide to ignore 'private.conf', it wouldn't stage it for commit if I do 'git commit .', but it would be normally working if I explicitly tell it to 'git commit private.conf'.

Please also take in account that

  • I know that I can just explicitly tell git which files to commit each time (e.g. "git commit source1.c source2.c"), but that's extremely convenient for me. Instead of that, I'd tell git to commit all files but 'private.conf'.
  • Some stackoverflow topics suggest to rename private.conf to private.conf.template, then run 'git rm --cached private.conf'. For some reasons that's also unconvenient for me. Please don't suggest me that. Thanks.
  • I know that I can also do 'git update-index --assume-unchanged private.conf' - and this would do exactly what I want, but only for my local git repository. What I'm searching for is a way to do that for remote branch (and all git repositories cloned from that remote branch as well).
vdudouyt
  • 843
  • 7
  • 14
  • You should not use `--assume-unchanged` in this case, but `--skip-worktree`. See here: https://stackoverflow.com/a/13631525/1615903 – 1615903 Apr 03 '17 at 11:38

1 Answers1

1

No, this is not possible. A tracked file is a tracked file and cannot be ignored.

Btw. using --assume-unchanged is rather dangerous, because you tell Git that his file is not changed and it will treat it like that, meaning Git can at any time discard you local changes if you switch branches, rebase, merge or similar.

If you want a files changes not being tracked, you need to delete it from the repository, like the suggestion with the .template file or .sample like I usually name such files.

Vampire
  • 35,631
  • 4
  • 76
  • 102