Archive of

Git Aliases for Clean Commits

Today I'd love to introduce three useful Git aliases to maintain clean code and intelligent staging.

Quick Setup

# 1. Remove trailing whitespace from modified files
git config --global alias.cleanup '!git -c color.status=false status -s | grep -v "^D\|^.D" | cut -c4- | xargs -r -I {} sed -i "s/[[:space:]]*$//" {}'

# 2. Stage only substantive changes (ignore whitespace)  
git config --global alias.stagewhitespace '!git reset . && git add -N . && git diff -w -b | git apply --cached'

# 3. Combine both operations
git config --global alias.smartadd '!git cleanup && git stagewhitespace'

Usage

git cleanup         # Clean trailing spaces only
git stagewhitespace # Stage content changes only
git smartadd        # Clean + smart staging

What Each Alias Does

cleanup

  • Removes trailing whitespace from all modified files
  • Skips deleted files to avoid errors
  • Handles ANSI color codes in git status output

stagewhitespace

  • Resets staging area
  • Marks new files as intent-to-add
  • Stages only meaningful content changes
  • Ignores pure whitespace modifications

smartadd

  • Runs cleanup first, then stagewhitespace
  • One command for clean, intelligent staging

Key Features

  • Safe: Filters out deleted files to prevent errors
  • Smart: Handles new files correctly
  • Clean: Maintains consistent code formatting
  • Focused: Stages only substantive changes

Technical Details

The aliases handle several edge cases:

  • ANSI color codes in git output (disabled with -c color.status=false)
  • Deleted files that would cause sed errors (filtered with grep -v "^D\|^.D")
  • New untracked files (handled with git add -N)
  • Empty file lists (handled with xargs -r)

Perfect for teams that want clean commits without manual whitespace management.

网友语录 - 第42期 - 伟大成就需要的是以年为单位的积累,而不是每周都冲刺

这里记录我的一周分享,通常在周六发布。


梨梨原上草 @svuoalnalnis 公司把保洁外包给一间公司,常来的就那么几个面孔。时间长了,你就能体会她们之间的差别。

有时候一走进厨房,你就知道今天来上班的肯定是其中的某一个。而另外一些天,不用具体看脸也知道来摸鱼的是哪几个……

其实想对其中几个说,你们可能干啥都会做得很好,不限于保洁。只要时间允许,我的活也能干。


还真是这样。一生要是每本书都一字一句的读完,确实读不了几千本。但真正值得一字一句读完的书完全没有那么多,你需要略读上万本书(甚至可以更多)才能找出为数不多值得读一次又一次的那些书。一本书翻了几页放下,没什么,很多书没有读完,没什么。没有读完的那些书,书自己也有责任。


戚小诺 我问小九怎么表达他的愤怒,他说他的脑子里会有一个白色小人,一个黑色小人,黑色小人想要去干架:冲啊!我要干架!白色小人就在一边劝架:算了算了,不要打架,也许打不赢会受伤,爸爸妈妈还会担心。然后自己就会冷静很多。——头脑特工队没白看哈😂😂


memoryza 人们天生就是高效的改进者,而只有极少数会愿意从零开始


失败不可怕,一蹶不振才可怕

反馈是变得更好的关键。正如蓝迪波什所说:"人之所以会改变,是因为获得了反馈"。"失败"的本质是一种强反馈,它告诉我们这样或者此时不行,我们需要调整。在这个世界上,只要我们的生命还在继续(留得青山在),就没有真正的失败(不怕没柴烧),有的只是不断调整的过程。一个人的成长速度,取决于他得到反馈的频率和质量。因此,我们应该勇于改变并珍视每一次的反馈,正是它们引导着我们一步步实现人生目标。


真正重要的工作都不是一口气完成的,而是反复回到同一主题,慢慢打磨。像居里夫人发现放射性元素那年夏天,也去乡下休假、爬山。伟大成就需要的是以年为单位的积累,而不是每周都冲刺。别被高强度伪忙碌欺骗,真正的生产力,是以自然节奏、长期愿景,持续推进关键事务


生活若总是愿意吃苦,就有吃不完的苦;若总是抱怨生活,就有抱怨不完的生活。总觉得前路还长,却不知不觉就进入四十几五十几。能改善生活质量的钱一定要尽早花,早花早享受


调查期望不是让用户畅想这产品能具有什么功能,而是为了满足现有需求应该具有什么功能


LLM 的注意力其实是个滑动窗口,不持续提醒,很容易跑偏,这一点就跟我们管理一个想法很多的员工一个道理。(哎!人的注意力也是个滑动窗口。)