Loading...
Loading...
Compare original and translation side by side
/commitgit push/commitgit push@{u}git log ..@{u}UPSTREAM_REF=$(git rev-parse --abbrev-ref @{u} 2>/dev/null)UPSTREAM_REF-u origin <branch>UPSTREAM_REMOTE=$(echo "$UPSTREAM_REF" | cut -d/ -f1) # e.g., "origin" from "origin/main"
git fetch "$UPSTREAM_REMOTE" # MUST succeed — abort entire workflow on failure@{u}originupstream/main@{u}git status # Uncommitted changes and branch info
git log @{u}.. --oneline # Local-only commits (ahead count)
git log ..@{u} --oneline # Remote-only commits (behind count)
git log @{u}.. --merges --oneline # Merge commits in local historyAfter git fetch origin:
+-- Local ahead, remote has nothing -> just push (no pull needed)
+-- Local behind, no local commits -> git pull --ff-only
+-- Diverged:
| +-- Local has merge commits? -> git pull --no-rebase (merge)
| +-- >20 local commits to replay? -> git pull --no-rebase (merge)
| +-- Few commits, no merges -> git pull --rebase
| +-- Any pull fails? -> abort, show state, ask user
+-- @{u} not configured -> commit, git push -u origin <branch>@{u}git log ..@{u}UPSTREAM_REF=$(git rev-parse --abbrev-ref @{u} 2>/dev/null)UPSTREAM_REF-u origin <branch>UPSTREAM_REMOTE=$(echo "$UPSTREAM_REF" | cut -d/ -f1) # 例如,从"origin/main"中提取"origin"
git fetch "$UPSTREAM_REMOTE" # 必须执行成功——失败则中止整个工作流@{u}originupstream/main@{u}git status # 未提交的更改和分支信息
git log @{u}.. --oneline # 仅存在于本地的commit(超前数量)
git log ..@{u} --oneline # 仅存在于远程的commit(落后数量)
git log @{u}.. --merges --oneline # 本地历史中的merge commit执行git fetch origin后:
+-- 本地超前,远程无新提交 -> 直接推送(无需拉取)
+-- 本地落后,无本地commit -> git pull --ff-only
+-- 分支分叉:
| +-- 本地存在merge commit? -> git pull --no-rebase(merge)
| +-- 需要重放的本地commit超过20个? -> git pull --no-rebase(merge)
| +-- 少量commit,无merge -> git pull --rebase
| +-- 任何拉取操作失败? -> 中止,展示状态,询问用户
+-- 未配置@{u} -> 提交,执行git push -u origin <branch>git status # See untracked files (NEVER use -uall flag)
git diff --staged # See staged changes
git diff # See unstaged changes
git log -10 --oneline # Recent commits for style referencegit add [specific files] # Prefer specific files over "git add -A"
# Sandbox-safe commit (NEVER use heredoc — sandbox blocks /tmp)
# For multi-line messages:
mkdir -p "$TMPDIR" && printf '%s\n' "subject line" "" "Body details here" > "$TMPDIR/commit_msg.txt" && git commit -F "$TMPDIR/commit_msg.txt"
# For single-line messages:
git commit -m "subject line"
git status # Verify commit succeeded--no-verifygit add -Agit add .<<EOF/tmp--amendgit status # 查看未跟踪文件(绝对不要使用-uall参数)
git diff --staged # 查看已暂存的更改
git diff # 查看未暂存的更改
git log -10 --oneline # 最近的commit,用于参考提交风格git add [specific files] # 优先指定具体文件,而非使用"git add -A"
# 沙箱安全提交(绝对不要使用heredoc——沙箱会阻止/tmp访问)
# 多行信息的提交方式:
mkdir -p "$TMPDIR" && printf '%s\n' "subject line" "" "Body details here" > "$TMPDIR/commit_msg.txt" && git commit -F "$TMPDIR/commit_msg.txt"
# 单行信息的提交方式:
git commit -m "subject line"
git status # 验证提交成功--no-verifygit add -Agit add .<<EOF--amendgit pull --ff-onlygit pull --ff-onlygit pull --no-rebasegit rebasegit merge --abortgit statusgit log @{u}.. --onelinegit log ..@{u} --onelinegit pull --no-rebasegit rebasegit merge --abortgit statusgit log @{u}.. --onelinegit log ..@{u} --onelinegit pull --rebasegit rebase --abortgit statusgit pull --rebasegit rebase --abortgit statusgit statusgit addgit rebase --continuegit rebase --abortgit addgit commitgit merge --abortgit statusgit addgit rebase --continuegit rebase --abortgit addgit commitgit merge --abortgit pushgit push -u origin <branch-name>| Error | Cause | Solution |
|---|---|---|
| Remote updated after our fetch | Re-fetch, re-evaluate state, sync again |
| New branch never pushed | |
| Branch has push restrictions | Notify user (need PR or permissions) |
git push --force--force-with-lease--forcereferences/force-push-guidelines.md--force-with-leasegit pushgit push -u origin <branch-name>| 错误 | 原因 | 解决方案 |
|---|---|---|
| 我们fetch后远程有更新 | 重新fetch,重新评估状态,再次同步 |
| 新分支从未推送过 | |
| 分支有推送限制 | 通知用户(需要提交PR或申请权限) |
git push --force--force-with-lease--forcereferences/force-push-guidelines.md--force-with-leasegit status # Should show "Your branch is up to date with 'origin/<branch>'"
git log -3 --oneline # Show recent commits for confirmationgit status # 应该显示"Your branch is up to date with 'origin/<branch>'"
git log -3 --oneline # 展示最近的commit供确认.claude/settings*.jsongit fetch origin.claude/settings*.jsongit fetch origingit log ..@{u} --onelinegit log ..@{u} --oneline
**Handle stash pop conflicts**:
- Notify user about conflicts after stash pop
- Show conflicting files
- Provide guidance: resolve conflicts, then `git add [files]`
- No `git stash drop` until conflicts resolved
**处理stash pop冲突:**
- 通知用户stash pop后出现冲突
- 展示冲突文件
- 提供指导:解决冲突,然后执行`git add [files]`
- 冲突解决前不要执行`git stash drop`undefinedundefined
If detached, notify user: "Cannot push from detached HEAD. Create a branch first: `git checkout -b <branch-name>`"
如果处于分离状态,通知用户:"无法从分离HEAD状态推送。请先创建分支:`git checkout -b <branch-name>`"git rev-parse --abbrev-ref @{u}-ugit rev-parse --abbrev-ref @{u}-ugit merge upstream/maingit pull --no-rebasegit log @{u}.. --merges --onelinegit merge upstream/maingit pull --no-rebasegit log @{u}.. --merges --onelinegit status # "nothing to commit, working tree clean"
git log @{u}.. --oneline # No output = no unpushed commitsgit status # "nothing to commit, working tree clean"
git log @{u}.. --oneline # 无输出 = 无未推送的commitgit fetch origingit fetch origingit add -Agit add .--no-verify<<EOF/tmp--force--force-with-lease$TMPDIRgit status--force-with-lease--forcegit add -Agit add .--no-verify<<EOF--force-with-lease--force$TMPDIRgit status--force-with-lease--forcerules/safety-and-git.mdprintfgit commit -F-m<<EOFrules/safety-and-git.mdprintfgit commit -F-m<<EOFreferences/conflict-resolution.mdreferences/force-push-guidelines.mdreferences/conflict-resolution.mdreferences/force-push-guidelines.md/commit/commitundefinedundefinedundefinedundefinedgit statusgit status