Follow

git stuff 

Something I learned in my ~3rd year of using git that has saved my ass many times: `git commit -am [commit message]` should be avoided. You inevitably end up auto-adding files you shouldn't, and the CLI encourages short commit messages.

Significantly better to do `git commit -v -a`. This pulls up your default editor and shows you the diff of the changes you are about to commit. You can see if any unwanted files/changes are about to be committed, and easily enter a verbose description.

git stuff 

@michcio seeing the diff while writing your commit message is so good

git stuff 

@darius this is kinda why i use just -a for commits which i'm confident are simple and git-cola for bigger projects

git stuff 

@michcio sometimes I forget that GUIs exist

git stuff 

@darius i had to use `git add -p -i` today because i made a headless persistent container for something and i think i prefer a GUI still

git stuff 

@darius oh, that's neat. I usually do rounds of git status, git add, and git rm --cached until I'm happy before commiting. The -v option seems like it might streamline things.

git stuff 

@polymerwitch yes definitely. It makes me much more confident about large commits because I can just read exactly what it is I am, uh, committing to

git stuff 

@darius this is one of the main things I try to communicate to junior devs: write verbose git commits! and make them a clean discrete idea as much as possible. all code is about communication and the commit message is a handy tool to figure out wtf the code is on about. I didn’t know about the ability to see the diff while writing! gonna update my alias

git stuff 

@christa Yes! I emphasize that doing this writes 90% of your pull request for you ahead of time, and it does so while your brain is still inside the specific task of coding so you are in the best place to explain what you were doing and why. The PR itself then just becomes a place to contextualize the commit(s) within the larger feature you are PR'ing.

git stuff 

@stelepami I've never seen this before, this is great! It's exactly how I was taught to write commits

git stuff 

@darius It's my favorite. It probably bugged me too much at my last job when the norm was just to write everything On the first line instead of using a header statement.

git stuff 

@stelepami honestly I do not think that is being overly picky

git stuff 

@darius I decided it was not worth fighting for. They also preferred merging instead of rebasing; I tried to convert people there but it wasnt intuitive for the folks who preferred to use the Intellij plusin to the command line. Eh. Contract's over.

git stuff 

@stelepami I think I would probably not try to convert people to rebasing while on a contract. Good commit messages are something even a beginner on day 1 of using git can do, and there's not really a failure state that can't be undone with --amend. Meanwhile, merge vs rebase is a pretty technical topic that can have unsafe failure states.

git stuff 

@darius There was potential to convert to full time which didn't pan out, but I was thinking long term.

git stuff 

@stelepami @darius, I'm still raw from having the third-year CS undergrads dismissing the requisite "CS & Society (Ethics)" course and the writing workshops I ran as a TA.

"I can write code, that should be enough."

re: git stuff 

@darius we (speaking on behalf of all of the practitioners of technologikal arts) have an unhealthy relationship with being terse to avoid triggering each others' "tl;dr" responses. I would like to propose we'd probably be much better off working to eliminate the "tl;dr" response by replacing it with a more mindful "nl;gr" response - "nicely long; great read!" - rather than becoming more and more terse.

git stuff 

@darius one of my favorite alternatives to git commit -a is using git add -u

it only stages changes in files that git already recognizes. of course sometimes you have to add new files in explicitly, then.

git stuff 

@redoak huh.. when I do git commit -a, it does not include untracked files. I'm on git v2.25.1

git stuff 

@darius ah, my mistake. no idea whether version has anything to do with it; i'd imagine it's just something i learned from an old coworker, forgot their reasoning, and scrambled up.

git stuff 

@darius This is a great tip. I have been using a vim plugin that I can run :Gdiff to see this, but this is much more convenient!

git stuff 

@robby @darius sometimes if I kinda did a lot of work and want to organize it better into logical commits, I do git add --patch to accept/reject each change manually.

Rinse repeat until all my changes are sorted into commits.

re: git stuff 

@darius Yeah the explicitness of which chunks i'm managing at any given moment is what I like most about magit (plus the ease of add --patching), this looks like a great alternative if I move back to the CLI

git stuff 

@darius there's even a ZMQ standard that, along with other things, documents extended commit messages.

https://rfc.zeromq.org/spec/42/

git stuff 

@darius enjoyed your "make a person", btw!
Will go in my toolbox for making deep (no pun intended) NPCs for roleplaying games!

git stuff 

@darius oh, this is good. I have an out-of-date bundle of dotfiles and scripts to set up my shell how I like it, I should revise that and add an alias for this, and a commit message template.

git stuff 

@darius i absolutely use that so i can review my diff

but i also almost exclusively use git add -p

git stuff 

@darius great tip! I’m personally a fan of splitting adding and committing into two steps:
1. git add -p
2. git commit

git stuff 

@darius Well, dang, it's probably... [counting on fingers] over four years since I started using git, and now you have just taught me about commit's -v flag! Awesome. Most of the time I commit something, I have a 'git diff --staged' running in an alternate tmux pane. I'll have to try this out.

git stuff 

@darius I used this for the first time today and it seems nice

git stuff 

@darius I have always added files, double checked the git diff separately, then git commit -m before, this combines those last two steps well

Sign in to participate in the conversation
Friend Camp

Hometown is adapted from Mastodon, a decentralized social network with no ads, no corporate surveillance, and ethical design.