偷偷摘套内射激情视频,久久精品99国产国产精,中文字幕无线乱码人妻,中文在线中文a,性爽19p

Claude Code現(xiàn)在能全自動(dòng)推送代碼了,立刻刪掉你的commit腳本!

人工智能
通過(guò)Claude Code的Stop鉤子實(shí)現(xiàn)自動(dòng)Git提交與推送,每次Claude Code完成代碼任務(wù)響應(yīng)時(shí)自動(dòng)執(zhí)行,解放雙手編程。


第一章:功能概述

核心功能:通過(guò)Claude Code的Stop鉤子實(shí)現(xiàn)自動(dòng)Git提交與推送

觸發(fā)時(shí)機(jī):每次Claude Code完成代碼任務(wù)響應(yīng)時(shí)自動(dòng)執(zhí)行

操作流程

檢查Git倉(cāng)庫(kù)變更

暫存所有更改

創(chuàng)建包含會(huì)話ID和時(shí)間戳的描述性提交

推送至遠(yuǎn)程倉(cāng)庫(kù)

顯示提交狀態(tài)通知

第二章:配置步驟

Step 1:創(chuàng)建鉤子腳本

? 腳本路徑:~/.claude/hooks/auto-commit-after-task.sh

#!/bin/bash
  # Auto-commit and push after Claude Code completes a task
  # This hook runs when Claude finishes responding (Stop event)
  set -e
  # Parse JSON input
  INPUT=$(cat)
  SESSION_ID=$(echo "$INPUT" | jq -r '.session_id // "unknown"')
  WORKING_DIR=$(pwd)
  # Only run if we're in a git repository
  if ! git rev-parse --git-dir > /dev/null 2>&1; then
      echo '{"systemMessage": "Not a git repository, skipping auto-commit", 
  "suppressOutput": true}'
      exit 0
  fi
  # Check if there are any changes to commit
  if git diff --quiet && git diff --cached --quiet; then
      echo '{"systemMessage": "No changes to commit", "suppressOutput": true}'
      exit 0
  fi
  # Get a brief summary of what changed for the commit message
  CHANGED_FILES=$(git status --short | head -5)
  NUM_FILES=$(git status --short | wc -l)
  # Create commit message
  TIMESTAMP=$(date '+%Y-%m-%d %H:%M:%S')
  COMMIT_MSG="Auto-commit after Claude Code session
  Session: $SESSION_ID
  Time: $TIMESTAMP
  Files changed: $NUM_FILES
  Changes:
  $CHANGED_FILES
  ?? Generated with Claude Code
  "
  # Stage all changes
  git add -A
  # Commit
  if git commit -m "$COMMIT_MSG" > /dev/null 2>&1; then
      # Try to push (silently fail if no remote or push fails)
      if git push > /dev/null 2>&1; then
          echo '{"systemMessage": "? Auto-committed and pushed changes", "suppressOutput":
   false}'
      else
          echo '{"systemMessage": "? Auto-committed changes (push failed - no remote or 
  auth issue)", "suppressOutput": false}'
      fi
  else
      echo '{"systemMessage": "?? Commit failed", "suppressOutput": true}'
  fi

? 核心邏輯:

解析JSON輸入獲取會(huì)話ID(jq依賴必需)

非Git倉(cāng)庫(kù)自動(dòng)跳過(guò)

無(wú)變更時(shí)跳過(guò)提交

生成包含5個(gè)文件變更摘要的提交信息(含會(huì)話ID/時(shí)間戳/文件數(shù))

提交失敗時(shí)返回警告,推送失敗時(shí)提示權(quán)限問(wèn)題

Step 2:設(shè)置腳本權(quán)限

? 執(zhí)行命令:chmod +x ~/.claude/hooks/auto-commit-after-task.sh

Step 3:配置Claude設(shè)置

? 修改~/.claude/settings.json

{
    "hooks": {
      "Stop": [
        {
          "hooks": [
            {
              "type": "command",
              "command": "/home/YOUR_USERNAME/.claude/hooks/auto-commit-after-task.sh"
            }
          ]
        }
      ]
    }
  }

關(guān)鍵提示:必須替換YOUR_USERNAME為實(shí)際用戶名

Step 4:重啟生效

? 重啟Claude Code后鉤子將在新會(huì)話激活

第三章:提交示例

提交信息格式

Auto-commit after Claude Code session
Session: 3e5e7a78-c91c-4c3f-842f-4294b4714c35
Time: 2025-10-09 20:07:11
Files changed: 3
Changes:
 M main.py
 M config.py
 A new_file.py
?? Generated with Claude Code

第四章:定制選項(xiàng)

僅提交不推送

? 刪除腳本中的推送代碼段

# Try to push (silently fail if no remote or push fails)
  if git push > /dev/null 2>&1; then
      echo '{"systemMessage": "? Auto-committed and pushed changes", "suppressOutput": 
  false}'
  else
      echo '{"systemMessage": "? Auto-committed changes (push failed - no remote or auth 
  issue)", "suppressOutput": false}'
  fi

替換為:

echo '{"systemMessage": "? Auto-committed changes", "suppressOutput": false}'

自定義提交信息

? 直接修改腳本中的COMMIT_MSG變量格式

臨時(shí)禁用鉤子

? 在settings.json中添加:

{
  "disableAllHooks": true
}

第五章:其他鉤子事件

支持的事件類型

Stop(本文使用)

SessionEnd(會(huì)話結(jié)束時(shí)觸發(fā))

PreToolUse/PostToolUse(工具調(diào)用前后)

UserPromptSubmit(用戶提交提示時(shí))

文檔參考https://docs.claude.com/en/docs/claude-code/hooks

第六章:故障排查

鉤子未運(yùn)行

執(zhí)行權(quán)限檢查ls -la ~/.claude/hooks/auto-commit-after-task.sh

依賴驗(yàn)證:安裝jq(Linux: sudo apt install jq / Mac: brew install jq

配置校驗(yàn):使用JSON驗(yàn)證器檢查settings.json語(yǔ)法

提交成功但推送失敗

? 檢查遠(yuǎn)程倉(cāng)庫(kù)配置:git remote -v

? 驗(yàn)證推送權(quán)限及SSH密鑰/憑證

查看運(yùn)行日志

? 在Claude Code輸出中檢查提示消息(如? Auto-committed and pushed changes

責(zé)任編輯:武曉燕 來(lái)源: 知識(shí)藥丸
相關(guān)推薦

2025-10-21 09:05:00

2025-10-30 16:23:47

Cursor 2.0人工智能智能體

2023-08-02 08:44:33

人工智能Kaggle科研繪圖

2011-10-09 13:16:50

LNMP生產(chǎn)服務(wù)器自動(dòng)安裝

2019-08-16 08:50:52

代碼日志程序員

2025-09-05 09:06:10

2020-08-14 08:00:39

Git數(shù)據(jù)層控制層

2025-08-14 08:37:58

2019-05-28 10:00:06

PHP代碼前端

2021-12-06 16:14:04

特斯拉FSD自動(dòng)駕駛

2025-09-01 08:58:00

2023-07-04 14:05:15

AI創(chuàng)意

2025-08-19 08:55:40

2025-09-30 09:05:00

2018-07-20 15:20:09

2025-07-23 08:27:53

2015-10-28 09:42:07

2025-09-12 09:12:00

ChatGPTAI工具

2025-09-18 16:18:23

2020-05-12 14:57:06

git commit代碼前端
點(diǎn)贊
收藏

51CTO技術(shù)棧公眾號(hào)