What is your process to create a new commit?
Is it just git commit -am? Or is it more sophisticated?
Mine used to be something like this:
for ...
For further actions, you may consider blocking this person and/or reporting abuse
I first do a
git diff
to review the changes I made and decide what I’m going to commit first if several commits are desired.Then I use
git add -p
. It’s a bit daunting at first, but you get used to it. It walks you through all the changes (as patch hunks) and you can decide whether to add (y
) it or not (n
). Then you have extra commands for more control, like add the whole file (a
) or skip it (d
), split the current hunk into smaller parts (s
), and even edit the patch hunk in your editor (e
).Since I’ve been doing this, my commits are much more atomic, because I don’t limit myself to committing whole files at a time. It’s also a great safeguard, because you actively look at anything you’re about to commit, and are less likely to commit debug statements, for example. You will still forget to add new files, though, I can guarantee it. ;-) (speaking of new files, you can add them with
git add -N my_new_file
to record the addition of the file without its contents. Then you see the whole file ingit diff
andgit add -p
, which is sometimes useful.The
-p
flag also works forreset
,checkout
(useful to remove debug print statements) andstash
.Editing the patches is more difficult, but it’s sometimes handy and you get used to it.
Instead of
git add -p
, I use git-istage tool. For me is more handy thangit add -p
.I didn't know about
git add -N
, thanks, that will be a useful tool in my belt!I just use git-gui, it shows the diff, you can select lines or the whole file you can amend easily.
I just type
gg
to launch it and we're good to go.You don't have gui available to everywhere. Plus in most cases you can be faster through the CLI if you know how to use it.
At my work I have access to a graphical environment almost all the time. For other tools I agree with you that CLI can be faster (if you spend time configuring and learning it) but for git I've found that git-gui does just the right job for me without needing for customization.
Now that I think of it I haven't typed
git commit
in years ^That's pretty slick. 🤘