0

For ease of work I do some local hacks to my code that I do not wish to have commit.

For example, I might have some tests that are expensive to run locally and I always have them skipped so that they only run on the CD Pipeline.

Or maybe, I hardcode the response of an API to check the UI consistently without dependency on the backend.

Whenever I'm adding my real changes I do git add -p and consistently ignore these hacks, but work is pretty menial.

Is there a way to tell git something like, hey these changes I want to be always ignored. It could prompt me if I modify anything else on the files but not prompt me if I don't. Or maybe never ask for that blob unless it changes.

Of course I cannot just add them to .gitignore, they are important files that I want in my repository.

It is related to this question Git - Difference Between 'assume-unchanged' and 'skip-worktree' but in the linked questions the files that are ignored will never be modified.

In my case I do modify those files, but I want to review only when I do changes different from the ones that I already declined.

Gabriel Furstenheim
  • 2,969
  • 30
  • 27
  • Does this answer your question? [Git - Difference Between 'assume-unchanged' and 'skip-worktree'](https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree) – j6t Oct 24 '22 at 07:27
  • It is a partial solution. It will solve by full file which might be good enough, but not by blob. I have a big file and maybe there are 5 lines that I want (always and always same diff) ignored, but other changes I want to review – Gabriel Furstenheim Oct 24 '22 at 08:24
  • What about having a branch where you commit this change, merge the branch without getting the change using `-s ours` then you work on this branch – Ôrel Oct 24 '22 at 09:35
  • But how does that work when I want to open a pull request? I need to remove those changes, right? I don't see what would be the dev flow there – Gabriel Furstenheim Oct 24 '22 at 11:43
  • One way is adding some unique commented tags around your "ignorable" hunks and create a git alias which will pipe `git diff` output through a `sed` command (or a script) to strip off tagged hunks. Accordingly you can add corresponding scripts as a pre-commit hook to delete these hunks physically from modified files and post-commit hook to bring them back. Having some unique markers you can script up any desired result I hope which then will serve you transparently and permanently – bloody Oct 24 '22 at 12:32
  • Another issue are `modified` labels in `git status` which you can either accept or again create an alias with a script to detect the markers and conditionally strip irrelevant items from `git status` if only stuff between the markers implicate them. – bloody Oct 24 '22 at 12:38

0 Answers0