首页 > 解决方案 > 让本地仓库与远程同步

问题描述

我正在尝试将本地项目同步到现有的远程仓库。

从我的本地文件夹

git init
git remote add origin 
git fetch

问题是遥控器已经发散了,所以它提前了 2 或 3 次提交

我跑了

git status

并得到

On branch master
No commits yet
Untracked files:
  (use "git add <file>..." to include in what will be committed)

我需要将本地与远程同步。如果我跑

git pull origin master

我会收到一个错误:您对以下文件的本地更改将被合并覆盖。请提交您的更改或存储它们。我将无法存储,因为我没有初始提交。

如何跟踪文件并执行拉取请求以使本地存储库与远程同步?

更新 这是通过运行解决的

git fetch --all
git reset --hard origin/masater

标签: gitgitlab

解决方案


按着这些次序

  • 首先存储本地更改git stash
  • 然后拉动回购git pull origin master
  • 然后弹出隐藏git stash pop
  • 然后使用git add .
  • 然后提交并推送到master

推荐阅读