Git常见问题排查

清夏晚风

1. 推送冲突

1
2
3
4
5
6
7
# 错误提示
! [rejected] main -> main (non-fast-forward)

# 解决方案
git fetch origin
git rebase origin/main
git push -f

2. 拉取失败

1
2
3
4
5
# 错误提示
fatal: refusing to merge unrelated histories

# 解决方案
git pull origin main --allow-unrelated-histories

3. 分支混乱

1
2
3
# 重置到远程状态
git fetch --all
git reset --hard origin/main

4. 文件未跟踪

1
2
3
4
5
# 清理未跟踪文件
git clean -fd

# 恢复已修改文件
git checkout -- .

5. 认证问题

1
2
3
4
# 更新凭证缓存
git config --global credential.helper cache
# 设置超时时间(默认900秒)
git config --global credential.helper 'cache --timeout=3600'

6. 大文件提交

1
2
3
4
# 使用BFG清理历史
java -jar bfg.jar --delete-files *.psd
git reflog expire --expire=now --all
git gc --prune=now --aggressive

提示:使用 git reflog 可查看所有历史操作记录,用于恢复误操作

  • Title: Git常见问题排查
  • Author: 清夏晚风
  • Created at : 2026-01-13 16:48:23
  • Updated at : 2026-01-13 16:48:23
  • Link: https://blog.kimikkorow.eu.org/版本控制管理/Git/Git常见问题排查/
  • License: This work is licensed under CC BY-NC-SA 4.0.