Jesse Aldridge
Jesse Aldridge

Reputation: 8149

Make a local change without committing

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?

Upvotes: 0

Views: 469

Answers (1)

Tim Biegeleisen
Tim Biegeleisen

Reputation: 521997

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.

Upvotes: 1

Related Questions