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
Git merge and push
提问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/production
is 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 push
without 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 push
is 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/production
to track origin/production
, you can make the local/production
tracking branch for origin/production
using 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/production
here. Why not just production
? I am suspecting you already have production
tracking origin/production
and maybe use local/production
for you local development. In this case a reasonable work flow is like this:
PS我想知道您local/production
在这里选择的分支名称。为什么不只是production
?我怀疑您已经有了production
跟踪,origin/production
并且可能local/production
用于您的本地开发。在这种情况下,一个合理的工作流程是这样的:
git pull origin production:production
to pull the changes to yourproduction
- If there are new commits in
production
, that islocal/production
is behind then either rebase yourlocal/production
onproduction
(or mergeproduction
onlocal/production
) - the moment you want to push your changes,
merge
orcherry-pick
your commits toproduction
and push the changes withgit push origin production: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
.