I got told off very seriously today for using git commit too often. I don't think I commit too often, but it seems to distract my colleague and gets on his nerves. I have an alias on my Mac where typing 'ggg' creates a commit with no message. Perhaps my colleague was a bit irritable because we had a panic raising problem with some bug. But it makes me wonder if I could use some Emacs script where upon pressing some short-cut I could save a file and do a commit at the same time. Has anybody been in this situation? How did you solve it? What has happened?
Asked
Active
Viewed 398 times
1
-
3You can commit as often as you want, your colleague should never even see that. Just squash your commits prior to pushing is all. Or alternatively, change you `git commit` to `git commit --amend` – Andrew C Dec 04 '14 at 23:34
-
1ruby_object: If you're *pushing* the sorts of commits you describe to a remote branch that other team members will be pulling from, then I'm not surprised you got a talking to. A commit with no message is terrible, and if your commit is so incoherent that you can't even think of a sensible commit message to describe what it does, then that's obviously not a commit you should ever push. You want the commit log to be a useful history of development, not just a history of what you were typing at random points during the day. Autosaves are great, but don't pollute everyone's log in the process. – phils Dec 05 '14 at 05:35
-
As Andrew says, you can *amend* the most-recent commit (which replaces it instead of adding a new one), and you can use *interactive rebasing* to re-order and squash together several commits into a smaller number of more-useful commits. You should certainly take the time to learn about these facilities. There's also nothing wrong with pushing your un-squashed commits to a development branch for backup purposes -- so long as no one is going to be merging that branch. – phils Dec 05 '14 at 05:38
-
@Andrew C - My colleague can see that if he is sat next to me watching over my shoulder. Also, I know the --squash option and use it a lot. The problem is that switching windows to go to terminal distracts him and gets on his nerves. – ruby_object Dec 05 '14 at 07:37
-
Ah *that* kind of "pair". You might have made it clearer that this was primarily about someone watching over your shoulder? (That's not necessarily the first thing that springs to mind if pair programming isn't your normal arrangement.) – phils Dec 05 '14 at 07:55
1 Answers
1
You could consider magit, and add a script which would:
- commit at every save (or every few minutes like those mentioned here or the
ryuslash/git-auto-commit-mode
project) with a "!squash
" comment - allow you (still through magit) to
rebase -i --autosquash
, in order to get a smaller set of commits, and to revise their comments, making them meaninful and worthy of being published (ie pushed).
See "Trimming Git Commits/Squashing Git History" for more.
See also "An introduction to Magit, an Emacs mode for Git".
In that kind of local history mode (where you are producing a lot of commits), it is best to make those changes in a dedicated local branch, and to rebase/squash in a "public" branch" (meaning add your revised commits on top of a branch you intend to push, then reset your local branch on top of the public branch).
-
I didn't find a solution I would be satisfied with. I can't make git-wip to be ran on my mac, can't make git-auto-commit-mode to be activated selectively on certain branches. Looks like I am left on my own here. The easiest way seems to be modification of git-auto-commit-mode or writing my own solution. – ruby_object Dec 05 '14 at 15:04
-
@ruby_object I agree. For a selective process depending on the branch, your best option remains to write your own (and publish it on GitHub for others to benefit from it ;) ) – VonC Dec 05 '14 at 15:08
-
Slowly I'm getting there. https://github.com/bigos/wipscript and https://github.com/bigos/git-auto-commit-mode – ruby_object Dec 10 '14 at 21:01
-