4 ms·
This is why I work in graphical clients (GitKracken being my current preference). They make interactive staging of individual files or lines utterly trivial. I
by gregmac 8y ago
This is why I work in graphical clients (GitKracken being my current preference). They make interactive staging of individual files or lines utterly trivial.
I do partial commits significantly more often than committing everything, and often do things like a couple commits, checkout another branch (and GitKracken does an auto stash + apply) then commit a separate fix there before switching back to the original branch.
Also there are several other things it makes easier: being able to multi-select commits and see a combined diff, quicky diff between two random branches, and just generally browsing back through history. And importantly, it's easy to do all this without having to remember, copy/paste or type any branch names or commit hashes.
- gdfasfklshg4 8y agoJust an FYI if you ever lack access to GitKraken Git gui does line by line staging. It is not as pretty but it works well.
- gregmac 8y agoI'd say it's also not as functional. With a GUI you can click around and browse through other files, as well as stage/unstage with the same interface. With the CLI, all you can do is cycle through "Stage this hunk [y,n,q,a,d,e,?]?" prompts, and if you mess up, you have to exit completely and do `git reset --patch` and cycle through those prompts again (at least, I don't know another way to do that). Actually it's a bit worse because it has even more options: Unstage this hunk [y,n,q,a,d,j,J,g,/,s,e,?]? ? y - unstage this hunk n - do not unstage this hunk q - quit; do not unstage this hunk or any of the remaining ones a - unstage this hunk and all later hunks in the file d - do not unstage this hunk or any of the later hunks in the file g - select a hunk to go to / - search for a hunk matching the given regex j - leave this hunk undecided, see next undecided hunk J - leave this hunk undecided, see next hunk s - split the current hunk into smaller hunks e - manually edit the current hunk ? - print help If you use this all the time and get used to the commands, and are also good at picturing the separate pieces you are trying to commit in your head, it's probably fully functional. If you're like me, and come back to your code after an unrelated 1hr meeting (or lunch) and are trying to sort out the 3 or 4 separate changes you did earlier in the day to make nice logical commits... good luck.
- gdfasfklshg4 8y agoGit gui is a GUI that is part of the core git product...
- gregmac 8y agoOh! Wow, sorry, I didn't even know that existed (run `git gui` to view). Thanks! And you're right: it's completely functional for doing partial commits, but I agree definitely not as pretty.
- u801e 8y ago> With the CLI, all you can do is cycle through "Stage this hunk [y,n,q,a,d,e,?]?" prompts, and if you mess up, you have to exit completely and do `git reset --patch` and cycle through those prompts again (at least, I don't know another way to do that). Actually it's a bit worse because it has even more options ... You can get a hybrid of the two if you use commands like recountdiff (from patchutils) and git-apply --cached. I do this by reading the output of git diff into vim, editing diff hunks and running recountdiff on those hunks, and running git-apply --cached. If I mess up, I can always read the output of git diff --cached and run git-apply -R --cached to unstage that hunk. I find it better than using the CLI menu driven tool that you refer to.