Search code examples
gitatlassian-sourcetreestaging

How to automatically stage files in SourceTree


Every time I want to commit changes I've made, I have to check the box "Unstaged files" even though I'd previously committed them, and have only modified their contents.

I can't find a setting for this anywhere. Is there one? If not, is there a reason? And/or is there a workaround?

Thanks


Solution

  • What you're facing is called a two stage commit. This is actually tremendously useful:

    https://softwareengineering.stackexchange.com/questions/69178/what-is-the-benefit-of-gits-two-stage-commit-process-staging

    1. Split work into separate commits.

    You've probably many times opened a file to write a single-line fix, but at the same time you spotted that the formatting was wrong, some documentation could be improved, or some other unrelated fix. With other RCSes you'd have to write that down or commit it to memory, finish the fix you came for, commit that, and then return to fix the other stuff (or create a ball-of-mud commit with unrelated stuff). With Git you just fix all of it at once, and stage+commit the single line separately, with git add -i or git-gui.

    1. Don't break the build.

    You're working on a complicated modification. So you try different things, some of which work better than others, some which break things. With Git you'd stage things when the modification made things better, and checkout (or tweak some more) when the modification didn't work. You won't have to rely on the editor's undo functionality, you can checkout the entire repo instead of just file-by-file, and any file-level mistakes (such as removing a file that has not been committed or saving+closing after a bad modification) does not lead to lots of work lost.

    See also: