git常见问题记录

119 阅读1分钟

报错

fatal: refusing to merge unrelated histories

If you're sure you want to merge these two unrelated projects, you can do so with the --allow-unrelated-histories option. Here’s how you do it:

  1. Pull the changes from the repository using the following command:
git pull origin branch_name --allow-unrelated-histories
  1. Then, resolve any conflicts if they exist.
  2. Commit and push your changes to the repository.

.git体积过大

.git文件历史记录过大,影响打包效率,解决方案:

  1. 强制删除历史记录:操作麻烦、有风险,需要所有人重新clone
  2. git项目迁移:
    • 操作简单速度快,可以完整保留旧的历史记录
    • 需要修改打包发布域地址,注意迁移时代码不要漏,迁移后注意测试
    • 适合多人团队协作

error: Pulling is not possible because you have unmerged files.

原因:vscode提交时会先pull再commit,这会导致修改的commit没有提交又pull不了 解决方案:

1.手动commit

  • 先解决冲突
  • git add .
  • git commit -m "xxx"
  • git pull
  • 合并后后push

2.重新合并

git merge --abort // 终止合并 
git reset --merge // 重置合并 
git pull

再执行方案1