git Git合并和推送

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13597494/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-10 14:59:39  来源:igfitidea点击:

Git merge and push

gitgithubbranchpush

提问by Martin B.

I am starting with Git, so I feel that this question could be the newbiest question of day because this task is so simple, but it's causing a terrible headache..

我是从 Git 开始的,所以我觉得这个问题可能是当天最新鲜的问题,因为这个任务非常简单,但它引起了一个可怕的头痛..

I have 2 local branches:

我有 2 个本地分支机构:

  • master
  • local/production
  • 掌握
  • 本地/生产

And 2 remotes:

和 2 个遥控器:

  • master
  • production
  • 掌握
  • 生产

I need to pass local changes to production. So, my workflow was:

我需要将本地更改传递给生产。所以,我的工作流程是:

git checkout local/production
git merge master
git commit
git push

git merge:Seems Work fine, it detected all differences.

git merge:似乎工作正常,它检测到所有差异。

git commit:

提交:

On branch local/production

Your branch is ahead of 'origin/production' by 2 commits.

nothing to commit (working directory clean)

在分支本地/生产

您的分支比 'origin/production' 领先 2 次提交。

无需提交(工作目录干净)

And git push:

git push:

Everything up-to-date

一切都是最新的

So that's all, I couldn't push my changes to remote repository.

就是这样,我无法将更改推送到远程存储库。

采纳答案by FooF

Root cause:To cut the explanation short, it appears to me that your local/productionis not tracking origin/production. You can check this with git branch -avv.

根本原因:简而言之,在我看来,您local/production没有跟踪origin/production. 您可以使用git branch -avv.

About git push: Note that git pushwithout arguments will update allthe remote branches that have updated in your local tracking branches (from the git-push(1)manual page):

关于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).

Because the result of simple git pushis sometimes little unexpected if forgotten what changes done in local branches, I personally like to explicitly specify which branches I want to push. In your case it seems this is what you want to do:

因为git push如果忘记了本地分支做了什么更改, simple 的结果有时会有点出乎意料,所以我个人喜欢明确指定我要推送的分支。在您的情况下,这似乎是您想要做的:

git push origin local/production:production

If you want local/productionto track origin/production, you can make the local/productiontracking branch for origin/productionusing option -u:

如果要local/production跟踪origin/production,可以创建local/production跟踪分支以origin/production使用选项-u

git push -u origin local/production:production

(only required once). Then you can pull from origin to local/production.

(只需要一次)。然后你可以从原点拉到local/production.

Executive Summary:you need to understand the concept of tracking branch and the peculiar semantics of git push.

执行摘要:您需要了解跟踪分支的概念和git push.

P.S.I am wondering about your choice of your branch name local/productionhere. Why not just production? I am suspecting you already have productiontracking origin/productionand maybe use local/productionfor you local development. In this case a reasonable work flow is like this:

PS我想知道您local/production在这里选择的分支名称。为什么不只是production?我怀疑您已经有了production跟踪,origin/production并且可能local/production用于您的本地开发。在这种情况下,一个合理的工作流程是这样的:

  1. git pull origin production:productionto pull the changes to your production
  2. If there are new commits in production, that is local/productionis behind then either rebase your local/productionon production(or merge productionon local/production)
  3. the moment you want to push your changes, mergeor cherry-pickyour commits to productionand push the changes with git push origin production:production.
  1. git pull origin production:production将更改拉到您的 production
  2. 如果有新的提交production,即local/production是背后则要么衍合local/productionproduction(或合并productionlocal/production
  3. 当您想要推送您的更改,merge或者cherry-pick您提交production并使用git push origin production:production.