There's this file on my project that I need to modify whenever I run the web app locally. I basically need to comment out a function call to an external service. I realize this should be properly fixed by making a fake client or something, but the code in question is owned by another team. I want to be able to comment out the code, and then make a bunch of other changes without worrying about accidentally pushing the stubbed out code to master. I realize I can commit individual files, but this is a pain and I'd rather just be able to do git commit -am "bla bla"
. I guess I could add the problem file to my .gitignore
, but I do work with the file occasionally so this is somewhat inconvenient. Is there a better way to deal with this situation?
Asked
Active
Viewed 233 times
0

Jesse Aldridge
- 7,991
- 9
- 48
- 75
1 Answers
1
You may try using update-index
here:
git update-index --assume-unchanged <your_file.ext>
This option will tell Git to temporarily ignore changes to your_file.ext
. Running git status
will not report this file, even if you made changes to it.
Note that if you accidentally do git add
to your file directly, it will still be added to the index. But this option is a safety precaution which should at least make it harder for you to push changes to your_file.ext
.

Tim Biegeleisen
- 502,043
- 27
- 286
- 360
-
1Another option is to commit those changes to a different branch and keep that rebased atop `master`. This way you have a clear view of your own changes and there is no magic going on. `update-index --assume-unchanged` can be a cause of confusion. – jsageryd Mar 23 '18 at 06:12
-
2@jsageryd Good suggestion, and I always feel that if there is a file where sometimes it should be versioned, and sometimes not, that the root problem is a workflow issue. Any solution is really something of a hack. – Tim Biegeleisen Mar 23 '18 at 06:13
-
2`skip-worktree` is preferred over `assume-unchanged`, see [here](https://stackoverflow.com/questions/13630849/git-difference-between-assume-unchanged-and-skip-worktree/13631525#13631525) – 1615903 Mar 23 '18 at 07:01
-
@1615903 I have read your link, interesting, I did not know about this. – Tim Biegeleisen Mar 23 '18 at 07:24