GIT 推送不将提交推送到远程

Tom*_*rts 5 git push commit git-remote

我一直在开发 git 存储库,并且一直将本地更改推送到远程服务器......直到最近。当我执行 git Push 时,它说一切都是最新的。事实上,我已经比远程版本提前了 3 个提交,但它没有得到我的更改。

我已经尝试过发布在各个地方的 git log -1, git reset --hard 解决方案,但这并不能解决任何问题。我是否需要更改该数字以反映我领先的提交数量?

假设我有 5 个提交,为了简洁起见,命名为 1 到 5。我的本地版本是 5,远程版本是 2。Gitk 在提交 5 处显示我的 MASTER,在提交 2 处显示远程/origin/master。我需要 git将我的本地版本重置为 2(或 3,未推送到远程的第一个提交)?我的改变会发生什么?git 文档说 --hard 将放弃任何更改,这是否意味着它们将完全丢失?我想保留这 3 次提交的提交历史记录,因为进行了相当多的更改。

LAF*_*ica 3

首先仔细检查您的配置。

  1. 确保你确实推动了它。
  2. 确保您已将其推到您认为已推到的位置。

可以帮助您什么:

$ git log --full-history // is your commit really there?
$ git reflog // operation history
$ git remote -v // what are your remotes? 
$ git remote show DESIRED_REPO // do you have the remote repo you wanted to push to configured? the DESIRED_REPO?
Run Code Online (Sandbox Code Playgroud)

最后,确保您使用正确的推送符号:

  1. git push public和之间是有区别的git push --repo=public。第一个总是推送到公共,第二个仅当您推送的分支的远程未设置时。
  2. 如果您的分支的名称与远程分支的名称不同,这可能会产生影响。

$ git push remote local_branch:remote_branch // I've made this error today by swapping places, with remote_branch:local_branch Git will not find the branch to update.

希望这可以帮助。就我而言,在重新检查我尝试过的命令时仔细重新阅读手册有助于并揭示问题(交换分支名称)。