根本原因:为了缩短解释,在我看来,您local/production没有跟踪origin/production。您可以使用git branch -avv.
关于git push:请注意,git push不带参数将更新本地跟踪分支中已更新的所有远程分支(来自git-push(1)手册页):
git push ... [<repository> [<refspec>...]]
The special refspec : (or +: to allow non-fast-forward updates) directs git to
push "matching" branches: for every branch that exists on the local side, the
remote side is updated if a branch of the same name already exists on the remote
side. This is the default operation mode if no explicit refspec is found (that is
neither on the command line nor in any Push line of the corresponding remotes
file---see below).
因为git push如果忘记在本地分支中做了哪些更改,simple 的结果有时会出乎意料,所以我个人喜欢明确指定要推送哪些分支。在您的情况下,这似乎是您想要做的:
git push origin local/production:production
如果要local/production跟踪origin/production,可以使用选项创建local/production跟踪分支:origin/production-u
git push -u origin local/production:production
(只需要一次)。然后你可以从原点拉到local/production.
内容提要:您需要了解跟踪分支的概念以及git push.
PS我想知道您local/production在这里选择的分支名称。为什么不只是production?我怀疑您已经进行了production跟踪origin/production,并且可能local/production用于本地开发。在这种情况下,一个合理的工作流程是这样的:
git pull origin production:production将更改拉到您的production
- 如果有新的提交
production,那local/production是落后的,那么要么重新建立你local/production的基础production(或合并production在local/production)
- 您想要推送更改的那一刻,
merge或者cherry-pick您的提交production并使用git push origin production:production.