如何在离线时快进分支

Spa*_*ker 8 git offline

我如何快速转发分支机构,当我git fetch上网期间编辑时,现在我处于离线状态,并希望快速前进到我之前提取的状态.

例如,我离线并执行以下操作:

$ git checkout develop
Switched to branch 'develop'
Your branch is behind 'origin/develop' by 37 commits, and can be fast-forwarded.
  (use "git pull" to update your local branch)
Run Code Online (Sandbox Code Playgroud)

在尝试使用时,git pull我得到:

$ git pull
ssh: Could not resolve hostname <hostname>: Name or service not known
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
Run Code Online (Sandbox Code Playgroud)

在这种情况下我需要使用什么命令?

ara*_*aer 6

因为git pull基本上是git fetch+ git merge你已经做过fetch而且离线时不能再做,你只需要这样做git merge origin/develop.

或者git reset --hard origin/develop,即使没有快进,你也可以做到.

编辑:更多选项.另一种方法是git branch -f develop origin/develop在切换到它之前做- 你不能改变当前分支,但只要它不是最新的,你就可以将任何分支"更新"到任何状态.对于当前分支,您必须使用git reset.


axi*_*iac 6

git pullgit fetch是后跟 的快捷方式git merge

git fetch访问远程存储库(如果远程存储库位于另一台计算机上,则需要网络连接)。git merge仅使用您计算机上已存在的数据进行操作;它根本不关心你的网络连接。

既然你已经做了git fetch你需要做的就是运行另一半:git merge

  • `git merge --ff-only` 用于快进。 (2认同)