I'm a Perforce veteran who is moving our organization over to git. One thing I'm stuck on is how to manage large commits (I'm not referring to many different changes at once -- which I know isn't optimal -- but rather, a single type of change that affects many files at once). For example, let's say I add a parameter to a function that is called in dozens of files. Using the git command line with a visual diff tool, what's the best way to review all of my changes before committing? In practical terms I might spread this review out over a period of time, or might make a few more changes after reviewing some of my files, then get back to the unreviewed files.
In short, what I'm looking for is a way to easily difftool files one at a time and then mark them as reviewed. I know there are many UI solutions out there, but I'm interested in a native git solution.
Rejected ideas:
- Keep all files unstaged, then diff them one at a time, and stage a file if I like the diff. The problem with this idea is that it's cumbersome to type out the full paths of every file to do the diff (and then to stage it), since files may be sprinkled across many paths.
- Use interactive add mode (
git add -i
). The problem with this idea is that you can't diff unstaged files. Meaning that for this to work I would have to do some weird gyrations where I'd stage everything, then after a file passes my review I would actually unstage it, then at the end I'd swap the staged and unstaged files before commit. Gross. - Use patch mode. This is very cool, but doesn't seem to work with a visual difftool.
- Use
git gui
. This one is actually really close, but I haven't found a way to easily run difftool on each file with a double-click or hotkey.
Ironically, git add -i
would work perfectly for my needs if it didn't reverse the meaning of diff. i.e. by default, diff works on unstaged changes, but during an interactive add, diff only works on staged changes. This is perplexing to me, especially since the point of git add
is to stage files.
All thoughts are appreciated! Thank you for your help.