Imagine this scenario: you're working on a feature that requires touching lots of files, and you've got a lot of things staged, and a lot of things not staged (like debugging code, temporary comments for yourself to remember to do/undo certain things and not forget to add bits that you didn't yet have time to add), and then you see a simple one-line change that you must make, but which belongs in its own commit.
Is there any way to simply commit that without pulling everything out of the staging area that you've meticulously added, without stashing (and risking losing your careful selections of what to stage and what not to stage) and just commit that one line?
I realize that fiddling with multiple staging areas would probably make this possible, but I'm hoping there is a simpler solution than that. Some switch that lets me skip the staging area would be more convenient than mucking about with GIT_INDEX_FILE
to have 2 of them.
My ideal solution would be something sort of like this:
git commit --skip-stage --patch ./app/models/whatever.rb
If this is impossible, then I will simply stash and use --index
when I pop it back, and hope I didn't accidentally do something between stashing and popping that breaks the ability to cleanly restore the index.
Because I know someone will wonder "if you know about --index
with git stash pop
, why are you asking this question? Because it is as much about pushing the envelope of what I can do with Git as it is about solving a practical problem. Just because one solution to a problem exists doesn't mean it is the best solution or that one should stop looking for alternatives. That applies to all of life, not just Git.